-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathicon_downloader.py
31 lines (26 loc) · 1.05 KB
/
icon_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import json
import os
# Note: This does not fetch all icons from all the jsons
# Manually configure it to fetch what's only needed
json_file = 'some_json_file.json' #'../ascension_materials.json'
raw_data = open(json_file)
json_data = json.load(raw_data)
hd_folder = 'some_download_folder' #'../iconsHD'
file_type = '.png'
if not(os.path.exists(hd_folder)):
os.makedirs(hd_folder)
# For Json Structures { "main" : {"id":{info}, "id":{info}, "id":{info} } }
mainKey = 'character'
for id, info in json_data[mainKey].items():
file_name = info['clear_name']
if 'icon' in info:
with open(f"{hd_folder}/{file_name}{file_type}", "wb") as img_file:
img_file.write(requests.get(info['icon']).content)
# For Json Structures { "main" : [ {info}, {info}, {info} ] }
# mainKey = 'character_types'
# for info in json_data[mainKey]:
# file_name = info['name']
# if 'icon' in info:
# with open(f"{hd_folder}/{file_name}{file_type}", "wb") as img_file:
# img_file.write(requests.get(info['icon']).content)