Skip to content

Instantly share code, notes, and snippets.

@strayge
Last active February 28, 2022 12:19
Show Gist options
  • Save strayge/f9fc711b52a388a7eefd211c7f867c04 to your computer and use it in GitHub Desktop.
Save strayge/f9fc711b52a388a7eefd211c7f867c04 to your computer and use it in GitHub Desktop.
Download public and secret gists (token required)
# based on https://stackoverflow.com/a/16233710
import json
import urllib
from subprocess import call
import requests
import os
import math
import sys
USER = sys.argv[1]
TOKEN = sys.argv[2]
gists = []
for i in range(20):
r = requests.get(f'https://api.github.com/gists?page={i}', auth=(USER, TOKEN))
resp = r.json()
if not resp:
break
for gist in resp:
# TODO: fix dups
gists.append(gist)
print('Found gists : {len(gists}')
f=open('./contents.txt', 'w+')
startd = os.getcwd()
for i, gist in enumerate(gists):
print(f'{i} / {len(gists)}')
gistd = gist['id']
gistUrl = 'git@gist.github.com:' + gistd + '.git'
if os.path.isdir(gistd):
os.chdir(gistd)
call(['git', 'pull', gistUrl])
os.chdir(startd)
else:
call(['git', 'clone', gistUrl])
if gist['description'] == None:
description = ''
else:
description = gist['description'].replace("\r",' ').replace("\n",' ')
f.write(f"id={gist['id']} public={gist['public']} url={gistUrl} description={description}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment