Created
June 28, 2019 02:05
-
-
Save tomoyk/5fa3af2ab25d7b662026c0ed8dcdd168 to your computer and use it in GitHub Desktop.
Gistにアップロードしたファイルを全て取得してくるスクリプト. 実行前にdatディレクトリを作成しておく.
This file contains 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
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