mirror of
https://github.com/jlengrand/twitterboard.git
synced 2026-03-10 08:51:22 +00:00
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:
BIN
twiderboard.db
BIN
twiderboard.db
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user