Skip to content

Instantly share code, notes, and snippets.

@matbor
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save matbor/6f83b07ee511bdd7dc7c to your computer and use it in GitHub Desktop.

Select an option

Save matbor/6f83b07ee511bdd7dc7c to your computer and use it in GitHub Desktop.
Just playing with Tweepy / Twitter Streaming api.
#uses tweepys/twitter streaming api, problem with using this is that you dont always get ALL the tweets.
#https://dev.twitter.com/streaming/overview/request-parameters#follow
from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
#print(data)
decoded = json.loads(data)
print('@%s : %s' % (decoded['user']['screen_name'],decoded['text']))
#print(decoded)
return True
def on_error(self, status):
print(status)
if __name__ == '__main__':
l = StdOutListener()
# Consumer keys and access tokens, used for OAuth
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
# OAuth process, using the keys and tokens
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#go for it...
stream = Stream(auth, l)
#stream.filter(track=['basketball']) # keyword search
stream.filter(follow=['55432787']) # username search, needs to the user id, ie. @3aw693 = 55432787
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment