forked from DEViantUA/ENCard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_name_card.py
36 lines (29 loc) · 1.51 KB
/
update_name_card.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
32
33
34
35
36
import aiohttp
import asyncio
async def fetch_data(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
data = await response.json()
return data
else:
print(f"Error: {response.status}")
return None
link_image = "https://gi.yatta.moe/assets/UI/namecard/{image}.png"
link_icon = "https://gi.yatta.moe/assets/UI/namecard/{icon}.png"
default_icon = "https://gi.yatta.moe/assets/UI/namecard/UI_NameCardIcon_0.png"
default_image = "https://gi.yatta.moe/assets/UI/namecard/UI_NameCardPic_0_P.png"
json_new = {}
async def main():
charter_list = await fetch_data("https://gi.yatta.moe/v2/ru/avatar?vh=42F2")
for key in charter_list["data"]["items"]:
data_charter = await fetch_data(f"https://gi.yatta.moe/v2/ru/avatar/{key}?vh=42F2")
if data_charter["data"]["other"] is None:
json_new[key] = {"id": 210001, "icon": default_icon, "image": default_image}
continue
output_string = data_charter["data"]["other"]["nameCard"]["icon"].replace("Icon_", "Pic_")
output_string += "_P"
json_new[key] = {"id": data_charter["data"]["other"]["nameCard"]["id"], "icon": link_icon.format(icon = data_charter["data"]["other"]["nameCard"]["icon"]), "image": link_image.format(image = output_string)}
print(json_new)
if __name__ == '__main__':
asyncio.run(main())