Skip to content

Instantly share code, notes, and snippets.

@sw331
Created December 7, 2016 15:32
Show Gist options
  • Select an option

  • Save sw331/2fed6e8c39e42a7c5063ec6aebf44441 to your computer and use it in GitHub Desktop.

Select an option

Save sw331/2fed6e8c39e42a7c5063ec6aebf44441 to your computer and use it in GitHub Desktop.
class MyListener(StreamListener):
def on_data(self, data):
try:
with open('python0.json', 'a') as f:
tweet = json.loads(data)
if tweet['coordinates']:
print(1)
f.write(data)
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=['sick'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment