Created
November 16, 2016 18:00
-
-
Save okjodom/8f33faa6781dab680998663720590bfe 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
import os | |
import requests | |
import json | |
import tweepy | |
from tweepy import Stream, StreamListener, OAuthHandler | |
# add keys from yout twitter app. create your app at http://apps.twitter.com/ | |
consumer_key = '' | |
consumer_secret = '' | |
access_token = '' | |
access_token_secret = '' | |
class dataListener(StreamListener): | |
def on_data(self, data): | |
try: | |
# save the data in raw_data.json file | |
with open('raw_data.json', 'a') as rd: | |
rd.write(data) | |
# auto filter | |
tweet = json.loads(data) | |
print(tweet) #load test, success | |
self.filterData(tweet) | |
rd.close() | |
except BaseException as e: | |
print('Error on data: %s' % str(e)) | |
return True | |
def on_error(self, status): | |
print(status) | |
return True | |
# the eavesdropper | |
listener = dataListener(10) | |
# authenticate | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
# initiate | |
stream = Stream(auth,listener) | |
gday = ['#GISDayinUoN_2016', '#GISapplication', '#gisday'] #gis day tags | |
stream.filter( track = gday ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment