The stream can now be closed properly.

Next objective is to be able to create/display a leaderboard for a given tag.
This commit is contained in:
Julien Lengrand-Lambert
2013-01-10 11:03:08 +01:00
parent a3a63c357b
commit 43308a5b85
6 changed files with 27 additions and 9 deletions

BIN
sav.db Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -130,12 +130,12 @@ class Counter():
raise ElementException # FIXME : Take care
except ElementException:
self.invalidate(Tweet)
self.invalidate(session, tweet)
self.logger.error("ElementException : Could not process %s !" % (tweet))
self.flush(session)
def invalidate(self, tweet):
def invalidate(self, session, tweet):
"""
Invalidates a tweet so that it is not recrawled by the counter
and can be verified later

View File

@@ -81,12 +81,12 @@ class Tweet(Base):
# Boolean that is set to True if Tweet cannot be processed correctly
invalid = Column(Boolean)
def __init__(self, author, created, inserted, crawled, source, text):
def __init__(self, author, created, inserted, source, text):
self.eu = EncodingUtils() # used to switch to unicode
self.author = self.eu.to_unicode(author)
self.created = self.eu.to_unicode(created)
self.crawled = crawled
self.crawled = False
self.inserted = inserted
self.source = self.eu.to_unicode(source)
self.hashtag = ''

View File

@@ -45,7 +45,6 @@ class StreamSaverListener(StreamListener):
tweet = Tweet(status.author.screen_name,
status.created_at,
datetime.datetime.now(),
False,
status.source,
status.text)
@@ -70,6 +69,9 @@ class StreamSaverListener(StreamListener):
def on_timeout(self):
print 'Snoozing Zzzzzz'
def on_delete(self):
return False
def format_hashtags(self, hashs):
"""
Returns the same list of hashtags in unicode format

View File

@@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import signal
from tweepy import Stream
@@ -10,13 +11,28 @@ from data import engine_url
# most trendy hashtags currently
trendy = ["#smartiphone5BNOLotto", "#enkötüsüde", "#GiveMeThatGlobeIphone5", "#SilivriyeÖzgürlük", "#CiteNomesFeios", "#121212concert", "#ItsNotCuteWhen", "#nowplaying", "#Blessed", "#breakoutartist"]
print "Trends streamed will be : "
print trendy
# ---------
def stop_handler(signal, frame):
"""
Detects when the user presses CTRL + C and stops the count thread
"""
global stream
# should be some kind of stream.stop() here
stream.disconnect()
print "You just closed the stream!"
# registering the signal
signal.signal(signal.SIGINT, stop_handler)
l = StreamSaverListener(trendy, engine_url)
myAuth = Authentification(oauth=True)
stream = Stream(myAuth.get_auth(), l)
print "Trends streamed will be : "
print trendy
stream.filter(track=trendy) # I need this to become a thread
print "Press CTRL + C to stop application"