Skip to content

Instantly share code, notes, and snippets.

@sbp
Created December 10, 2011 12:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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