Created
March 23, 2016 11:17
-
-
Save mikexine/e3cc62d932be8fa06141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import config | |
from tweepy import Stream | |
from tweepy.streaming import StreamListener | |
from tweepy import OAuthHandler | |
auth = OAuthHandler(config.consumer_key, config.consumer_secret) | |
auth.set_access_token(config.access_token, config.access_secret) | |
class MyListener(StreamListener): | |
def on_data(self, data): | |
try: | |
with open('json/bruxelles.json', 'a') as f: | |
f.write(data) | |
print "tweet saved." | |
return True | |
except BaseException as e: | |
print("Error on_data: %s" % str(e)) | |
return True | |
def on_error(self, status): | |
print(status) | |
return True | |
twitter_stream = Stream(auth, MyListener()) | |
twitter_stream.filter(track=['#Bruxelles', "#Brussels", "#brusselslockdown", "#zaventem", "prayforbruxelles", "prayforbelgium", "prayforbrussels"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment