Skip to content

Instantly share code, notes, and snippets.

@msawangwan
Created January 7, 2019 21:04
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 msawangwan/ede63fba1ea163da44a3757416f8b2a6 to your computer and use it in GitHub Desktop.
Save msawangwan/ede63fba1ea163da44a3757416f8b2a6 to your computer and use it in GitHub Desktop.
[python][gist][api] tool for downloading all the files in a single gist (by gist id)
#!/usr/bin/env python
import sys
import requests
api = 'https://api.github.com'
gist_id = '' # YOUR ID HERE, COULD BE PASSED IN AS AN ARG
print('fetching latest revisions ..')
r = requests.get(f'{api}/gists/{gist_id}')
payload = r.json()
if not payload:
print('error: empty payload ..')
sys.exit(1)
files = payload['files']
for filename in files:
print(f'downloading {filename} ..')
dl = requests.get(files[filename]['raw_url'])
with open(filename, 'wb') as fd:
fd.write(dl.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment