Commit 36f06827 authored by Janez K's avatar Janez K

twitter streams

parent cb543a65
from django.core.management.base import NoArgsCommand
from streams.models import *
class Command(NoArgsCommand):
help = 'see a list of all streams'
option_list = NoArgsCommand.option_list
def handle_noargs(self, **options):
import time
self.stdout.write("Working on streams...")
self.stdout.flush()
while True:
streams = Stream.objects.filter(active=True)
for stream in streams:
#self.stdout.write(u"\nChecking stream "+unicode(stream)+"...\n")
#self.stdout.flush()
#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(u"<"+str(now)+">Executing "+unicode(stream)+"...")
self.stdout.flush()
stream.execute()
self.stdout.write("done!\n")
self.stdout.flush()
#print stream.execute()
time.sleep(1)
#self.stdout.write(".")
#self.stdout.flush()
...@@ -11,6 +11,8 @@ class Command(NoArgsCommand): ...@@ -11,6 +11,8 @@ class Command(NoArgsCommand):
while True: while True:
streams = Stream.objects.filter(active=True) streams = Stream.objects.filter(active=True)
for stream in streams: for stream in streams:
#self.stdout.write(u"\nChecking stream "+unicode(stream)+"...\n")
#self.stdout.flush()
#preverimo ce je ze dost casa pretekl #preverimo ce je ze dost casa pretekl
import django import django
now = django.utils.timezone.now() now = django.utils.timezone.now()
...@@ -19,8 +21,16 @@ class Command(NoArgsCommand): ...@@ -19,8 +21,16 @@ class Command(NoArgsCommand):
if delta_seconds > stream.period: if delta_seconds > stream.period:
stream.last_executed = now stream.last_executed = now
stream.save() stream.save()
#self.stdout.write("-") self.stdout.write(u"Executing "+unicode(stream)+"...")
#self.stdout.flush() self.stdout.flush()
try:
stream.execute()
except:
import traceback
self.stdout.write("\n ERROR in executing stream:\n")
traceback.print_exc(file=self.stdout)
self.stdout.write("done!\n")
self.stdout.flush()
#print stream.execute() #print stream.execute()
time.sleep(1) time.sleep(1)
#self.stdout.write(".") #self.stdout.write(".")
......
...@@ -17,6 +17,12 @@ class Stream(models.Model): ...@@ -17,6 +17,12 @@ class Stream(models.Model):
period = models.IntegerField(default=60) period = models.IntegerField(default=60)
active = models.BooleanField(default=False) active = models.BooleanField(default=False)
def stream_visualization_widgets(self):
return self.workflow.widgets.all().exclude(abstract_widget__streaming_visualization_view='')
def reset(self):
self.widget_data.all().delete()
def execute(self,workflow=None,outputs={}): def execute(self,workflow=None,outputs={}):
if workflow is None: if workflow is None:
workflow = self.workflow workflow = self.workflow
......
{% extends "website/base.html" %}
{% load url from future %}
{% block "streamnav" %}
<div class="navbar">
<div class="navbar-inner">
<a class="brand">{{stream}}</a>
<ul class="nav">
{% for w in stream.stream_visualization_widgets %}
<li {% if widget.pk == w.pk %}class="active"{% endif %}><a href="{% url 'stream widget visualization' stream.pk w.pk %}">{{w}}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}
This diff is collapsed.
This diff is collapsed.
.brand {
font-family: 'Condiment', cursive;
}
\ No newline at end of file
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
<link href="{{STATIC_URL}}bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> <link href="{{STATIC_URL}}bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Condiment' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Condiment' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="{{STATIC_URL}}bootstrap/js/bootstrap.js"></script>
<script src="{{STATIC_URL}}js/fancybox/jquery.fancybox-1.3.4.js"></script>
<script src="{{STATIC_URL}}js/signuplogin.js"></script>
<!-- Le fav and touch icons --> <!-- Le fav and touch icons -->
<link rel="shortcut icon" href="images/favicon.ico"> <link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png"> <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
...@@ -52,7 +57,7 @@ ...@@ -52,7 +57,7 @@
<div class="navbar navbar-fixed-top"> <div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner"> <div class="navbar-inner">
<div class="container"> <div class="container">
...@@ -65,9 +70,9 @@ ...@@ -65,9 +70,9 @@
<div class="nav-collapse"> <div class="nav-collapse">
<ul class="nav pull-right"> <ul class="nav pull-right">
<li class="active"><a href="{% url 'website index' %}">Home</a></li> <li {% block "homeactive" %}{% endblock %}><a href="{% url 'website index' %}">Home</a></li>
<li><a href="{% url 'the index' %}" class="{% if not user.is_authenticated %}must_login{% endif %}">Start working</a></li> <li {% block "workflowactive" %}{% endblock %}><a href="{% url 'the index' %}" class="{% if not user.is_authenticated %}must_login{% endif %}">Start working</a></li>
<li><a href="{% url 'existing workflows' %}">Explore workflows</a></li> <li {% block "exploreactive" %}{% endblock %}><a href="{% url 'existing workflows' %}">Explore workflows</a></li>
<li><a class="{% if not user.is_authenticated %}must_login{% endif %}" href="{% if user.is_authenticated %}{% url 'logout' %}{% endif %}{% if not user.is_authenticated %}{% url 'website index' %}{% endif %}">{% if not user.is_authenticated %}Log in{% endif %}{% if user.is_authenticated %}Log out{% endif %}</a></li> <li><a class="{% if not user.is_authenticated %}must_login{% endif %}" href="{% if user.is_authenticated %}{% url 'logout' %}{% endif %}{% if not user.is_authenticated %}{% url 'website index' %}{% endif %}">{% if not user.is_authenticated %}Log in{% endif %}{% if user.is_authenticated %}Log out{% endif %}</a></li>
</ul> </ul>
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
...@@ -77,6 +82,11 @@ ...@@ -77,6 +82,11 @@
</div> </div>
<div class="container"> <div class="container">
{% block "streamnav" %}
{% endblock %}
{% block 'container' %} {% block 'container' %}
{% endblock %} {% endblock %}
...@@ -134,10 +144,6 @@ ...@@ -134,10 +144,6 @@
<!-- Le javascript <!-- Le javascript
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="{{STATIC_URL}}bootstrap/js/bootstrap.js"></script>
<script src="{{STATIC_URL}}js/fancybox/jquery.fancybox-1.3.4.js"></script>
<script src="{{STATIC_URL}}js/signuplogin.js"></script>
<div style="position:absolute;top:50%;left:50%;display:none;z-index:20;" class="ajax-loader"> <div style="position:absolute;top:50%;left:50%;display:none;z-index:20;" class="ajax-loader">
<img src="{{STATIC_URL}}images/ajax-loader-big.gif"> <img src="{{STATIC_URL}}images/ajax-loader-big.gif">
</div> </div>
......
{% extends 'website/base.html' %} {% extends 'website/base.html' %}
{% block "exploreactive" %}class="active"{% endblock %}
{% block 'container' %} {% block 'container' %}
{% for w in workflows %} {% for w in workflows %}
......
{% extends "website/base.html" %} {% extends "website/base.html" %}
{% load url from future %} {% load url from future %}
{% block "homeactive" %}class="active"{% endblock %}
{% block 'container' %} {% block 'container' %}
<div class="hero-unit"> <div class="hero-unit">
<h1>ClowdFlows</h1> <h1>ClowdFlows</h1>
......
...@@ -24,6 +24,25 @@ def streaming_collect_and_display_tweets(input_dict,widget,stream=None): ...@@ -24,6 +24,25 @@ def streaming_collect_and_display_tweets(input_dict,widget,stream=None):
swd.save() swd.save()
return {} return {}
def streaming_sentiment_graph(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): def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
import pickle import pickle
from pysimplesoap.client import SoapClient, SoapFault from pysimplesoap.client import SoapClient, SoapFault
...@@ -133,7 +152,10 @@ def streaming_twitter(input_dict,widget,stream=None): ...@@ -133,7 +152,10 @@ def streaming_twitter(input_dict,widget,stream=None):
tweet['id'] = tw.id tweet['id'] = tw.id
tweet['created_at'] = tw.created_at tweet['created_at'] = tw.created_at
tweet['text'] = unicode(tw.text).encode("utf-8") tweet['text'] = unicode(tw.text).encode("utf-8")
tweet['user'] = tw.user try:
tweet['user'] = tw.user['screen_name']
except:
tweet['user'] = ""
tweet['lang'] = tw.lang tweet['lang'] = tw.lang
tweets.append(tweet) tweets.append(tweet)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.