Skip to content

Instantly share code, notes, and snippets.

@andrewgiessel
Forked from tmcw/archive_tweets.py
Created July 31, 2012 21:39
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 andrewgiessel/3220819 to your computer and use it in GitHub Desktop.
Save andrewgiessel/3220819 to your computer and use it in GitHub Desktop.
Archive Tweets
import requests, os, glob, json
you = 'giessel'
data = 'tweets'
try: os.mkdir(data)
except Exception: pass
def run(max_id = False):
already = glob.glob("%s/*.json" % data)
start = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=%s&include_rts=true&count=200' % you
if max_id:
start = '%s&max_id=%s' % (start, max_id)
r = requests.get(start)
has_new = False
for t in r.json:
if ("%s/%s.json" % (data, t['id'])) not in already:
json.dump(t, open('%s/%s.json' % (data, t['id']), 'w'))
has_new = True
if has_new:
last = r.json.pop()
run(last['id'])
print 'starting twitter archive of @%s' % you
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment