Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active December 19, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5881856 to your computer and use it in GitHub Desktop.
Save tmcw/5881856 to your computer and use it in GitHub Desktop.
Back up Issues
import requests, os, glob, json, codecs
data = os.path.join(os.path.dirname(__file__), 'issues')
try: os.mkdir(data)
except Exception: pass
auth = ('USER', 'PASSWORD')
repo = 'REPO'
def run(page=1,state='open'):
print 'on page %s' % page
already = glob.glob("%s/*.json" % data)
start = 'https://api.github.com/repos/%s/issues?state=%s&page=%s' % (repo, state, page)
if page:
start = '%s?page=%s' % (start, page)
r = requests.get(start, auth=auth)
has_new = False
for t in r.json():
if ("%s/%s.json" % (data, t['id'])) not in already:
print 'downloading %s' % t['id']
json.dump(t, open('%s/%s.json' % (data, t['id']), 'w'))
has_new = True
else:
print '%s already stored' % t['id']
if has_new and 'next' in r.headers['Link']:
run(page + 1, state)
print 'starting gist archive of @%s' % repo
run(1, 'open')
run(1, 'closed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment