Update query_resource.py

This commit is contained in:
HibiKier 2022-02-19 20:03:40 +08:00 committed by GitHub
parent d8983bdcbf
commit 2b9cda40a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,9 +97,11 @@ async def init(flag: bool = False):
await download_resource_data(semaphore) await download_resource_data(semaphore)
await download_resource_type() await download_resource_type()
if not CENTER_POINT: if not CENTER_POINT:
if resource_label_file.exists():
CENTER_POINT = json.load(open(resource_label_file, "r", encoding="utf8"))[ CENTER_POINT = json.load(open(resource_label_file, "r", encoding="utf8"))[
"CENTER_POINT" "CENTER_POINT"
] ]
if resource_label_file.exists():
with open(resource_type_file, "r", encoding="utf8") as f: with open(resource_type_file, "r", encoding="utf8") as f:
data = json.load(f) data = json.load(f)
for id_ in data: for id_ in data:
@ -114,7 +116,7 @@ async def download_resource_data(semaphore: Semaphore):
icon_path.mkdir(parents=True, exist_ok=True) icon_path.mkdir(parents=True, exist_ok=True)
resource_label_file.parent.mkdir(parents=True, exist_ok=True) resource_label_file.parent.mkdir(parents=True, exist_ok=True)
try: try:
response = await AsyncHttpx.get(POINT_LIST_URL, timeout=5) response = await AsyncHttpx.get(POINT_LIST_URL, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
if data["message"] == "OK": if data["message"] == "OK":
@ -166,7 +168,7 @@ async def download_map_init(
if _map.exists() and os.path.getsize(_map) > 1024 * 1024 * 30: if _map.exists() and os.path.getsize(_map) > 1024 * 1024 * 30:
_map.unlink() _map.unlink()
try: try:
response = await AsyncHttpx.get(MAP_URL, timeout=5) response = await AsyncHttpx.get(MAP_URL, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
if data["message"] == "OK": if data["message"] == "OK":
@ -205,7 +207,7 @@ async def download_map_init(
async def download_resource_type(): async def download_resource_type():
resource_type_file.parent.mkdir(parents=True, exist_ok=True) resource_type_file.parent.mkdir(parents=True, exist_ok=True)
try: try:
response = await AsyncHttpx.get(LABEL_URL, timeout=5) response = await AsyncHttpx.get(LABEL_URL, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
if data["message"] == "OK": if data["message"] == "OK":
@ -251,7 +253,7 @@ async def download_image(
async with semaphore: async with semaphore:
try: try:
if not os.path.exists(path) or not is_valid or force_flag: if not os.path.exists(path) or not is_valid or force_flag:
if await AsyncHttpx.download_file(img_url, path, timeout=5): if await AsyncHttpx.download_file(img_url, path, timeout=10):
logger.info(f"下载原神资源图标:{img_url}") logger.info(f"下载原神资源图标:{img_url}")
if gen_flag: if gen_flag:
gen_icon(path) gen_icon(path)