diff --git a/mothra/urls.py b/mothra/urls.py index 2268a07ce38c439d05b62db4b07750ec1380aa0a..06920e5e953c4e6aa56ac53987aaaac24e794843 100644 --- a/mothra/urls.py +++ b/mothra/urls.py @@ -18,23 +18,24 @@ urlpatterns = patterns('', url(r'^', include('signuplogin.urls')), url(r'^', include('website.urls')), url(r'^workflows/', include('workflows.urls')), - url(r'^admin/', include(admin.site.urls)), - + url(r'^streams/', include('streams.urls')), + url(r'^admin/', include(admin.site.urls)), + url('^' + LOGIN_URL[1:] + '$', 'django.contrib.auth.views.login', name='login'), url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'), url(r'^change-password/$', 'django.contrib.auth.views.password_change', name='password change'), url(r'^password-changed/$', 'django.contrib.auth.views.password_change_done', name='password change done'), - + url(r'^password_reset/$', 'django.contrib.auth.views.password_reset'), url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'), url(r'^reset/(?P[0-9A-Za-z]{1,13})-(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm'), url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'), - + ) ## debug stuff to serve static media if DEBUG: urlpatterns += patterns('', - (r'^media/(?P.*)$', 'django.views.static.serve', + (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': STATIC_DOC_ROOT}), - ) \ No newline at end of file + ) diff --git a/streams/management/commands/run_streams.py b/streams/management/commands/run_streams.py index b495cdb4f612d7632f2513d452adc035a7353b79..d5af4723e70987c0e82977e8ffe6bf048b3b6e0c 100755 --- a/streams/management/commands/run_streams.py +++ b/streams/management/commands/run_streams.py @@ -5,15 +5,24 @@ class Command(NoArgsCommand): help = 'check for streams that need to be executed and execute them' option_list = NoArgsCommand.option_list def handle_noargs(self, **options): - streams = Stream.objects.filter(active=True) - for stream in streams: - #preverimo ce je ze dost casa pretekl - import django - now = django.utils.timezone.now() - delta = now - stream.last_executed - delta_seconds = delta.seconds + delta.days * 86400 - if delta_seconds > stream.period or 1==1: - stream.last_executed = now - stream.save() - print stream.execute() + import time + self.stdout.write("Working on streams...") + self.stdout.flush() + while True: + streams = Stream.objects.filter(active=True) + for stream in streams: + #preverimo ce je ze dost casa pretekl + import django + now = django.utils.timezone.now() + delta = now - stream.last_executed + delta_seconds = delta.seconds + delta.days * 86400 + if delta_seconds > stream.period: + stream.last_executed = now + stream.save() + #self.stdout.write("-") + #self.stdout.flush() + #print stream.execute() + time.sleep(1) + #self.stdout.write(".") + #self.stdout.flush() diff --git a/streams/urls.py b/streams/urls.py new file mode 100755 index 0000000000000000000000000000000000000000..0504593bed4c8b2a4dfd7817324f69ffabb89c05 --- /dev/null +++ b/streams/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls.defaults import patterns, include, url + +urlpatterns = patterns('', + url(r'^data/(?P[0-9]+)/(?P[0-9]+)/$', 'streams.views.stream_widget_visualization', name='stream widget visualization'), +) diff --git a/streams/views.py b/streams/views.py index 60f00ef0ef347811e7b0c0921b7fda097acd9fcc..fcc4f2e2dad1092d1a62d36fe51de70347aa8d58 100644 --- a/streams/views.py +++ b/streams/views.py @@ -1 +1,42 @@ -# Create your views here. +# helperji, context stvari +from django.shortcuts import render, get_object_or_404, redirect +from django.http import Http404, HttpResponse +from django.contrib import messages +from django.core import serializers +from django.utils import simplejson +from workflows.urls import * +from workflows.helpers import * +import workflows.interaction_views +import workflows.visualization_views +import sys +import traceback + +# modeli +from workflows.models import * +from django.contrib.auth.models import User + +from workflows.utils import * + +# auth fore +from django.contrib.auth.decorators import login_required + +#settings +from mothra.settings import DEBUG, FILES_FOLDER + +from streams.models import Stream + +import workflows.views + +#ostalo +import os + +@login_required +def stream_widget_visualization(request,stream_id,widget_id): + stream = get_object_or_404(Stream,pk=stream_id) + widget = get_object_or_404(Widget,pk=widget_id) + if widget.abstract_widget.streaming_visualization_view == '': + return Http404 + else: + view_to_call = getattr(workflows.views,widget.abstract_widget.streaming_visualization_view) + return view_to_call(request,widget,stream) + diff --git a/workflows/streaming/library.py b/workflows/streaming/library.py index 1c08c2482f8a495138f36809289d169a8da82f33..2db6f450aaff3c3e0632b2d8b91075bd4bd7fe66 100644 --- a/workflows/streaming/library.py +++ b/workflows/streaming/library.py @@ -5,6 +5,25 @@ Streaming widgets librarby @author: Janez Kranjc ''' +def streaming_collect_and_display_tweets(input_dict,widget,stream=None): + from streams.models import StreamWidgetData + if stream is None: + return {} + else: + try: + swd = StreamWidgetData.objects.get(stream=stream,widget=widget) + data = swd.value + except Exception as e: + swd = StreamWidgetData() + swd.stream = stream + swd.widget = widget + data = [] + swd.value = data + swd.save() + swd.value = input_dict['ltw']+swd.value + swd.save() + return {} + def streaming_tweet_sentiment_service(input_dict,widget,stream=None): import pickle from pysimplesoap.client import SoapClient, SoapFault diff --git a/workflows/streaming/templates/streaming_vizualizations/streaming/display_tweets.html b/workflows/streaming/templates/streaming_vizualizations/streaming/display_tweets.html new file mode 100755 index 0000000000000000000000000000000000000000..80106c7567bb5daf46cb541253ea3c73f09a7bc4 --- /dev/null +++ b/workflows/streaming/templates/streaming_vizualizations/streaming/display_tweets.html @@ -0,0 +1,22 @@ + + + + + + + + + + +{% for tweet in tweets %} + + + + + + +{% endfor %} + +
TextUserIdSentiment
{{tweet.text}}{{tweet.user.screen_name}}{{tweet.id}}{{tweet.sentiment}}
+ + diff --git a/workflows/streaming/views.py b/workflows/streaming/views.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6608b4a328c4f47ca31ec57282db4119e428075e 100644 --- a/workflows/streaming/views.py +++ b/workflows/streaming/views.py @@ -0,0 +1,42 @@ +# helperji, context stvari +from django.shortcuts import render, get_object_or_404, redirect +from django.http import Http404, HttpResponse +from django.contrib import messages +from django.core import serializers +from django.utils import simplejson +from workflows.urls import * +from workflows.helpers import * +import workflows.interaction_views +import workflows.visualization_views +import sys +import traceback + +# modeli +from workflows.models import * +from django.contrib.auth.models import User + +from workflows.utils import * + +# auth fore +from django.contrib.auth.decorators import login_required + +#settings +from mothra.settings import DEBUG, FILES_FOLDER + +#ostalo +import os + +from streams.models import * + +def streaming_collect_and_display_visualization(request,widget,stream): + try: + swd = StreamWidgetData.objects.get(stream=stream,widget=widget) + data = swd.value + except Exception as e: + swd = StreamWidgetData() + swd.stream = stream + swd.widget = widget + data = [] + swd.value = data + swd.save() + return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':swd.value})