Analyzing Social Media Data in Python
Alex Hanna
Computational Social Scientist
tweepy
from tweepy import Stream
import time
class SListener(Stream):
def __init__(self, api = None):
self.output = open('tweets_%s.json' %
time.strftime('%Y%m%d-%H%M%S'), 'w')
self.api = api or API()
...
from tweepy import OAuthHandler from tweepy import API auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = API(auth)
from tweepy import Stream listen = SListener(api)
stream = Stream(auth, listen)
stream.sample()
Analyzing Social Media Data in Python