def init(self):
auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
auth.set_access_token(self.access_token, self.access_token_secret)
try:
my_stream_listener = MyStreamListener
my_stream = tweepy.Stream(auth=auth,
listener=my_stream_listener(
crud=self.CRUD,
conn_sec=self.conn_sec,
conn_schema=self.conn_schema,
conn_table=self.conn_table))
# Choose the kind of stream - either bounding box or word track.
if self.search_word:
my_stream.filter(track=[self.search_word], async=True)
else:
my_stream.filter(locations=self.geo, async=True)
# Check if the connection stream is active and
# break if it is not. init() function will restart
# the connection stream.
self.running = my_stream.running
while True:
if not my_stream.running:
self.running = False
time.sleep(60) # Check each 60 sec.
break
except Exception as e:
logging.error(e)
pass
评论列表
文章目录