Skip to content

Instantly share code, notes, and snippets.

@sbp
Created December 10, 2011 12:04
Show Gist options
  • Save sbp/1454998 to your computer and use it in GitHub Desktop.
Save sbp/1454998 to your computer and use it in GitHub Desktop.
Download all of a user's gists
#!/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)
@willwade
Copy link

bit out of date sadly now. the Oauth stuff that is in the new API needs to be taken into account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment