Skip to content

Instantly share code, notes, and snippets.

@tomoyk
Created June 28, 2019 02:05
Show Gist options
  • Save tomoyk/5fa3af2ab25d7b662026c0ed8dcdd168 to your computer and use it in GitHub Desktop.
Save tomoyk/5fa3af2ab25d7b662026c0ed8dcdd168 to your computer and use it in GitHub Desktop.
Gistにアップロードしたファイルを全て取得してくるスクリプト. 実行前にdatディレクトリを作成しておく.
from urllib import request
import json
def main():
url = 'https://api.github.com/users/tomoyk/gists'
req = request.Request(url)
with request.urlopen(req) as res:
res_body = res.read().decode('utf-8')
dict_res = json.loads(res_body)
# print(dumped_res)
for item in dict_res:
for file in item.get('files').values():
fname = file.get('filename')
furl = file.get('raw_url')
print(f'+ Downloading {fname}')
request.urlretrieve(furl, 'dat/' + fname)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment