Skip to content

Instantly share code, notes, and snippets.

@graingerkid
Created March 30, 2017 13:13
Show Gist options
  • Save graingerkid/d871306403b70dd9e81fe952121161ad to your computer and use it in GitHub Desktop.
Save graingerkid/d871306403b70dd9e81fe952121161ad to your computer and use it in GitHub Desktop.
filter tweets which contain words
from twython import Twython # pip install twython
import time # standard lib
''' Go to https://apps.twitter.com/ to register your app to get your api keys '''
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
lis = [467020906049835008] ## this is the latest starting tweet id
for i in range(0, 16): ## iterate through all tweets
## tweet extract method with the last list item as the max_id
user_timeline = twitter.get_user_timeline(screen_name="craigaddyman",
count=200, include_retweets=False, max_id=lis[-1])
time.sleep(300) ## 5 minute rest between api calls
words = ['alcohol', 'drink', 'drunk', 'high', 'wasted']
for tweet in user_timeline:
for word in words:
if word in tweet['text']:
print tweet['text'] ## print the tweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment