Skip to content

Instantly share code, notes, and snippets.

@jcalabres
Last active January 12, 2020 13:57
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 jcalabres/086d972c38c0a9c2797f73dd4de4b908 to your computer and use it in GitHub Desktop.
Save jcalabres/086d972c38c0a9c2797f73dd4de4b908 to your computer and use it in GitHub Desktop.
Get all the gists of a user
# Download all public gist for a user
# by using v3 gist api (https://developer.github.com/v3/gists/)
import requests, json
from pathlib import Path
headers = {"content-type" : "application/json"}
url = 'https://api.github.com/users/jcalabres/gists'
r = requests.get(url, headers = headers)
# Downloading files
data = r.json()
counter = 0
for i in data:
files_node = i['files']
file_name = [k for k in files_node][0]
r = requests.get(files_node[file_name]['raw_url'])
f = open(str(Path.home())+'/scripts/gists/{}'.format(file_name), 'w')
f.write(r.text)
f.close()
print('Downloaded {}'.format(file_name))
counter += 1
print('{} files successfully downloaded.'.format(counter))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment