Skip to content

Instantly share code, notes, and snippets.

@mattmc3 mattmc3/ forked from fedir/
Last active Jul 28, 2019

What would you like to do?
Clone or update all user's gists #backup #github #gists #management
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -LJO
# chmod 755 ./
# USER=mattmc3 python3
from __future__ import absolute_import, division, print_function, unicode_literals
import json
import urllib
from subprocess import call
import os
import math
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
USER = os.environ['USER']
userurl = urlopen('' + USER)
public_gists = json.load(userurl)
gistcount = public_gists['public_gists']
print("Found gists : " + str(gistcount))
pages = int(math.ceil(float(gistcount)/perpage))
print("Found pages : " + str(pages))
f=open('./contents.txt', 'w+')
for page in range(pages):
pageNumber = str(page + 1)
print("Processing page number " + pageNumber)
pageUrl = '' + USER + '/gists?page=' + pageNumber + '&per_page=' + str(int(perpage))
u = urlopen (pageUrl)
gists = json.load(u)
startd = os.getcwd()
for gist in gists:
gistd = gist['id']
gistUrl = 'git://' + gistd + '.git'
if os.path.isdir(gistd):
call(['git', 'pull', gistUrl])
call(['git', 'clone', gistUrl])
if gist['description'] == None:
description = ''
description = gist['description'].replace("\r",' ').replace("\n",' ')
print(gist['id'], gistUrl, description, file=f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.