Skip to content

Instantly share code, notes, and snippets.

@blech
Last active August 30, 2015 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blech/65694 to your computer and use it in GitHub Desktop.
Save blech/65694 to your computer and use it in GitHub Desktop.
See /blech/mytweets
#!/usr/bin/python
# Incredibly cackhanded Twitter backup. Needs *lots* of work.
import urllib2
import simplejson as json
import base64
page = 1
posts = []
username = "username" # TODO take on command line or from .rc file
password = "password"
# base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
top_level_url = "http://twitter.com/"
password_mgr.add_password(None, top_level_url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
while (page < 10):
response = opener.open('http://twitter.com/statuses/user_timeline.json?count=200&page=%s' % page)
data = response.read()
tweets = json.loads(data)
print tweets
posts.extend(tweets)
page += 1
print json.dumps(posts)
print len(posts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment