Created
December 17, 2013 08:39
-
-
Save abelsonlive/8001861 to your computer and use it in GitHub Desktop.
hack to find links on twitter
This file contains hidden or 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 json | |
import tweepy | |
import os | |
import json | |
consumer_key = '' | |
consumer_secret = '' | |
access_key = '' | |
access_secret = '' | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
api = tweepy.API(auth) | |
class CustomStreamListener(tweepy.StreamListener): | |
def __init__(self, api): | |
self.api = api | |
super(tweepy.StreamListener, self).__init__() | |
def on_data(self, tweet): | |
data = json.loads(tweet) | |
print data['text'] | |
print data['entities']['urls'] | |
def on_error(self, status_code): | |
return True # Don't kill the stream | |
def on_timeout(self): | |
return True # Don't kill the stream | |
sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api)) | |
sapi.filter(track=['propublica', 'propub.ca']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment