Created
June 1, 2019 14:11
-
-
Save PhotonQuantum/ae0620f9808f7eb4e6effdde2bf5a838 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
import requests | |
import sys | |
import os | |
import json | |
from itertools import cycle | |
import base64 | |
from multiprocessing.dummy import Pool | |
url_detail = 'https://api.tuwan.com/apps/Welfare/detail?format=json&id=' | |
def download(params): | |
(url, fn, dir) = params | |
r = requests.get(url) | |
with open(dir + "/" + "{:0>2d}".format(fn) + ".jpg", 'wb') as f: | |
f.write(r.content) | |
print(str(fn) + " complete") | |
def conv_url(url): | |
url_split = url.split("/") | |
params = base64.b64decode(url_split[6]).decode("utf-8") | |
params_split = params.split(',') | |
params_split[1] = "1024" | |
params_split[2] = "0" | |
url_split[6] = base64.b64encode(",".join(params_split).encode("utf-8")).decode("utf-8") | |
return "/".join(url_split) | |
def main(): | |
r = requests.get(url_detail + sys.argv[1]) | |
detail = r.json() | |
os.mkdir(detail["title"]) | |
thumb_list = detail["thumb"] | |
thumb_list = list(map(conv_url, thumb_list)) | |
print("all: " + str(len(thumb_list))) | |
with Pool(4) as pool: | |
pool.map(download, zip(thumb_list, range(1, len(thumb_list)+1), cycle([detail["title"]]))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment