PamGram/modules/apihelper/client/components/remote.py

69 lines
2.3 KiB
Python
Raw Normal View History

2023-02-28 14:15:48 +00:00
from typing import List, Dict
2023-10-07 15:21:45 +00:00
from httpx import AsyncClient
2023-02-28 14:15:48 +00:00
2023-10-07 15:21:45 +00:00
from metadata.scripts.metadatas import RESOURCE_DEFAULT_PATH, RESOURCE_FightPropRule_URL
from utils.log import logger
2023-02-28 14:15:48 +00:00
class Remote:
"""拉取云控资源"""
2023-03-27 01:04:08 +00:00
BASE_URL = f"https://raw.githubusercontent.com/{RESOURCE_DEFAULT_PATH}"
2023-02-28 14:15:48 +00:00
CALENDAR = f"{BASE_URL}calendar.json"
BIRTHDAY = f"{BASE_URL}birthday.json"
2023-04-04 14:02:14 +00:00
MATERIAL = f"{BASE_URL}roles_material.json"
2023-10-07 15:21:45 +00:00
RULE = f"{RESOURCE_FightPropRule_URL}FightPropRule_starrail.json"
2023-02-28 14:15:48 +00:00
@staticmethod
async def get_remote_calendar() -> Dict[str, Dict]:
"""获取云端日历"""
try:
async with AsyncClient() as client:
req = await client.get(Remote.CALENDAR)
if req.status_code == 200:
return req.json()
return {}
2023-10-07 15:21:45 +00:00
except Exception as exc:
logger.error("获取云端日历失败: %s", exc_info=exc)
2023-02-28 14:15:48 +00:00
return {}
@staticmethod
async def get_remote_birthday() -> Dict[str, List[str]]:
"""获取云端生日"""
try:
async with AsyncClient() as client:
req = await client.get(Remote.BIRTHDAY)
if req.status_code == 200:
return req.json()
return {}
2023-10-07 15:21:45 +00:00
except Exception as exc:
logger.error("获取云端生日失败: %s", exc_info=exc)
2023-02-28 14:15:48 +00:00
return {}
2023-04-04 14:02:14 +00:00
@staticmethod
async def get_remote_material() -> Dict[str, List[str]]:
"""获取云端角色材料"""
try:
async with AsyncClient() as client:
req = await client.get(Remote.MATERIAL)
if req.status_code == 200:
return req.json()
return {}
2023-10-07 15:21:45 +00:00
except Exception as exc:
logger.error("获取云端角色材料失败: %s", exc_info=exc)
return {}
@staticmethod
async def get_fight_prop_rule_data() -> Dict[str, Dict[str, float]]:
"""获取云端圣遗物评分规则"""
try:
async with AsyncClient() as client:
req = await client.get(Remote.RULE)
if req.status_code == 200:
return req.json()
return {}
except Exception as exc:
logger.error("获取云端圣遗物评分规则失败: %s", exc_info=exc)
2023-04-04 14:02:14 +00:00
return {}