Commit 4fb2602a authored by Rémy Decoupes's avatar Rémy Decoupes
Browse files

handle stream deconnection : log error and re-start stream filter

parent 356de5b9
......@@ -146,18 +146,19 @@ if __name__ == '__main__':
tweetoutput = open(tweetouputfilename, 'w')
myStreamListener = Listener(tweetoutput, logger, keywordList)
stream = tweepy.Stream(auth=api.auth, listener=myStreamListener)
try:
logger.info("Start streaming")
# Could not filter on both ("AND") account AND hashtag because Twitter's API query only implements "OR"
# stream.filter(follow=accounttofollowedlist, track=hashtagtrackedList)
stream.filter(follow=accounttofollowedlist)
except KeyboardInterrupt:
logger.info("Stream Keyboard Interrupt")
logger.info("Collect tweets : proceeded normally")
except:
logger.error("Unexpected error: ", sys.exc_info()[0])
logger.info("Collect tweets : aborted")
finally:
stream.disconnect()
tweetoutput.close()
while True:
try:
logger.info("Start streaming")
# Could not filter on both ("AND") account AND hashtag because Twitter's API query only implements "OR"
# stream.filter(follow=accounttofollowedlist, track=hashtagtrackedList)
stream.filter(follow=accounttofollowedlist)
except KeyboardInterrupt:
logger.info("Stream Keyboard Interrupt")
logger.info("Collect tweets : proceeded normally")
stream.disconnect()
tweetoutput.close()
except Exception as ex:
logger.error("Unexpected error with stream. Try reconnect")
logger.error(ex.message, ex.args)
# logger.info("Collect tweets : aborted")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment