Created
January 7, 2019 21:04
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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