Last active
August 30, 2015 00:25
-
-
Save blech/65694 to your computer and use it in GitHub Desktop.
See /blech/mytweets
This file contains hidden or 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/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