Created
December 10, 2011 12:04
-
-
Save sbp/1454998 to your computer and use it in GitHub Desktop.
Download all of a user's gists
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 sys, os, urllib, json | |
user = sys.argv[1] | |
u = urllib.urlopen('http://gist.github.com/api/v1/json/gists/' + user) | |
bytes = u.read() | |
u.close() | |
gistdir = user + '-gists' | |
if os.path.exists(gistdir): | |
print >> sys.stderr, 'Error: Already exists: ' + gistdir | |
sys.exit(1) | |
os.mkdir(gistdir) | |
os.chdir(gistdir) | |
for gist in json.loads(bytes)[u'gists']: | |
repo = gist[u'repo'] | |
for name in gist[u'files']: | |
u = urllib.urlopen('http://gist.github.com/raw/%s/%s' % (repo, name)) | |
bytes = u.read() | |
u.close() | |
with open('%s.%s' % (repo, name), 'wb') as w: | |
w.write(bytes) | |
print 'Got %s.%s' % (repo, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bit out of date sadly now. the Oauth stuff that is in the new API needs to be taken into account