Skip to content

Instantly share code, notes, and snippets.

@gpetuhov
Created August 1, 2019 14:06
Show Gist options
  • Select an option

  • Save gpetuhov/206379dca137af53ffe398ca4b996902 to your computer and use it in GitHub Desktop.

Select an option

Save gpetuhov/206379dca137af53ffe398ca4b996902 to your computer and use it in GitHub Desktop.
Download all gists
# first: mkdir user && cd user && cp /path/to/get_gists.py .
# python3 get_gists.py user
# Run this N times, where N is the number of pages to download,
# each time changing page=X in download URL.
# Each page contains 100 gists.
# You can copy up to 3000 gists like this
# (for 3000 gists you will have to run this script 30 times).
# Code is taken from:
# https://gist.github.com/leoloobeek/3be8b835988e8d926a4387019370db8d
import requests
import sys
from subprocess import call
user = sys.argv[1]
# Change page number before downloading next page
# Page numbers start from 1 (NOT 0)
r = requests.get('https://api.github.com/users/{0}/gists?page=1&per_page=100'.format(user))
for i in r.json():
folder = i['description'][0:255] if i['description'] else i['id']
call(['git', 'clone', i['git_pull_url'], folder])
description_file = './{0}/description.txt'.format(folder)
with open(description_file, 'w') as f:
f.write('{0}\n'.format(i['description']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment