From 826395ea52b400afb81122222f680d90dbb3c2d0 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 19 Dec 2024 16:28:37 +0800 Subject: [PATCH] feat: mihomo map --- func/fetch_mihomo_map.py | 41 ++++++++++++++++++++++++++++++++++++++++ func/url.py | 2 ++ main.py | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 func/fetch_mihomo_map.py diff --git a/func/fetch_mihomo_map.py b/func/fetch_mihomo_map.py new file mode 100644 index 0000000..134a1b6 --- /dev/null +++ b/func/fetch_mihomo_map.py @@ -0,0 +1,41 @@ +import asyncio +from pathlib import Path + +import aiofiles + +from func.client import client, retry +from func.url import mihomo_map_url + +data_dir = Path("data") / "mihomo_map" +data_dir.mkdir(exist_ok=True, parents=True) +file_set = { + "characters.json", + "character_ranks.json", + "character_skills.json", + "character_skill_trees.json", + "character_promotions.json", + "light_cones.json", + "light_cone_ranks.json", + "light_cone_promotions.json", + "relics.json", + "relic_sets.json", + "relic_main_affixes.json", + "relic_sub_affixes.json", + "paths.json", + "elements.json", + "properties.json", + "avatars.json", +} + + +@retry +async def fetch_file(filename: str) -> None: + req = await client.get(mihomo_map_url + filename) + async with aiofiles.open(data_dir / filename, "wb") as f: + await f.write(req.content) + + +async def fetch_files(): + print("获取 mihomo map 文件") + tasks = [fetch_file(file) for file in file_set] + await asyncio.gather(*tasks) diff --git a/func/url.py b/func/url.py index 97b47df..209fff4 100644 --- a/func/url.py +++ b/func/url.py @@ -1,2 +1,4 @@ base_url = "https://api-static.mihoyo.com/common/blackboard/sr_wiki/v1" list_url = f"{base_url}/home/content/list" + +mihomo_map_url = "https://raw.githubusercontent.com/Mar-7th/StarRailRes/master/index_min/cn/" diff --git a/main.py b/main.py index b4af114..3cdbf51 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from func.fetch_light_cones import fetch_light_cones from func.fetch_materials import fetch_materials from func.fetch_relics import fetch_relics from func.fetch_src import move_files +from func.fetch_mihomo_map import fetch_files async def wiki(): @@ -23,6 +24,7 @@ async def bbs_photos(): async def main(): await wiki() await bbs_photos() + await fetch_files() if __name__ == "__main__":