-
-
Save AparaV/6facd7db460b905933cf908c8b919b89 to your computer and use it in GitHub Desktop.
import os | |
import time | |
import tweepy | |
from tweepy import OAuthHandler | |
from tweepy import Stream | |
from tweepy import StreamListener | |
def authenticate(): | |
'''Use credentials to authenticate user''' | |
consumerkey = os.environ.get('CONSUMER_KEY') | |
consumersecret = os.environ.get('CONSUMER_SECRET') | |
accesstoken = os.environ.get('ACCESS_TOKEN') | |
accesssecret = os.environ.get('ACCESS_SECRET') | |
auth = OAuthHandler(consumerkey, consumersecret) | |
auth.set_access_token(accesstoken, accesssecret) | |
api = tweepy.API(auth) | |
return auth, api | |
if __name__ == "__main__": | |
auth, api = authenticate() | |
'''Live streaming tweets for a specific interval of time''' | |
runtime = 60 #Tracking for 60 seconds | |
tweetstream = Stream(auth, StreamListener()) | |
tweetstream.filter(track=['twitter'], is_async=True) | |
time.sleep(runtime) | |
tweetstream.disconnect() |
v3 line 28; should be is_async=True
and should line 30 be tweetstream.disconnect()
?
Thank you for catching the typos and API updates @pilou-K75VJ and @stevenmcsorley!
Doesn't seem to work, I put some print statements after stream.filter
, time.sleep
and stream.disconnect
, everything prints but the console hangs. How can I terminate the whole process?
@Kwieeciol Not sure why the process will not terminate if you are able to successfully disconnect (as evidenced by your print statement after .disconnect()
). Maybe you have some other thread that is running? Or maybe there was a breaking change in recent API updates?
I am not actively maintaining this anymore. Perhaps, ask on stack overflow or open an issue on tweepy. I am happy to update the gist if you figure out the issue!
@AparaV, it's the only thread. I think the issue might be that the thread where stream.filter
is being ran doesn't terminate. Thanks anyways! I'll investigate the issue.
line 28, small typo : "filer" to "filter"