Skip to content

Instantly share code, notes, and snippets.

@thearchduke
Last active September 26, 2016 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thearchduke/e6dc73220a6c249840377ce57cd3b358 to your computer and use it in GitHub Desktop.
Save thearchduke/e6dc73220a6c249840377ce57cd3b358 to your computer and use it in GitHub Desktop.
try:
import cPickle as pickle
except:
import pickle
from twitter import *
import datetime
token = ''
token_key = ''
con_key = ''
con_secret = ''
twit = Twitter(auth=OAuth(token, token_key, con_key, con_secret))
limits = twit.application.rate_limit_status()
n = limits['resources']['statuses']['/statuses/user_timeline']['remaining']
all_tweets = twit.statuses.user_timeline(screen_name="Johngcole", count=200, include_retweets=False)
n -= 1
last_id = all_tweets[-1]['id']
while len(all_tweets) < 3200:
if n == 1:
break
more_tweets = twit.statuses.user_timeline(screen_name="Johngcole", count=200, max_id=last_id, include_retweets=False)
all_tweets += more_tweets
last_id = all_tweets[-1]['id']
# if you want to watch your progress:
print n, len(all_tweets)
n -= 1
# dump or do whatever with your all_tweets obj
pickle.dump(all_tweets, open('tweets_no_retweets.p', 'wb'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment