Skip to content

Instantly share code, notes, and snippets.

@mikexine
Created March 23, 2016 11:17
Show Gist options
  • Save mikexine/e3cc62d932be8fa06141 to your computer and use it in GitHub Desktop.
Save mikexine/e3cc62d932be8fa06141 to your computer and use it in GitHub Desktop.
#!/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