Created
September 21, 2012 17:00
-
-
Save chadwhitacre/3762666 to your computer and use it in GitHub Desktop.
Simple Twitter archiving script in Python
This file contains 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
#!/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