Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Created September 21, 2012 17:00
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 chadwhitacre/3762666 to your computer and use it in GitHub Desktop.
Save chadwhitacre/3762666 to your computer and use it in GitHub Desktop.
Simple Twitter archiving script in Python
#!/usr/bin/env python
import twitter
import simplejson
api = twitter.Api( consumer_key=''
, consumer_secret=''
, access_token_key=''
, access_token_secret=''
)
max_id = None
empty = False
fp = open('tweets.json', 'w')
while not empty:
raw = api.GetUserTimeline( screen_name=''
, count=200
, max_id=max_id
, include_rts=True
, include_entities=True
, contributor_details=True
, return_raw=True
)
parsed = simplejson.loads(raw)
print "downloaded {} tweets with max_id {}".format(len(parsed), max_id)
if parsed:
fp.write(raw + '\n')
max_id = parsed[-1]['id'] - 1
else:
empty = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment