2022-12-10 12:37:43 +00:00
|
|
|
import time
|
2023-10-19 13:55:12 +00:00
|
|
|
from typing import List, Dict
|
2022-12-10 12:37:43 +00:00
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
|
|
|
__all__ = ("AbyssTeam",)
|
|
|
|
|
|
|
|
|
|
|
|
class AbyssTeam:
|
2023-10-19 13:55:12 +00:00
|
|
|
TEAM_RATE_API = "https://homa.snapgenshin.com/Statistics/Team/Combination"
|
2022-12-10 12:37:43 +00:00
|
|
|
HEADERS = {
|
2023-10-19 13:55:12 +00:00
|
|
|
"Host": "homa.snapgenshin.com",
|
2022-12-10 12:37:43 +00:00
|
|
|
"Referer": "https://servicewechat.com/wxce4dbe0cb0f764b3/91/page-frame.html",
|
|
|
|
"User-Agent": "Mozilla/5.0 (iPad; CPU OS 15_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) "
|
|
|
|
"Mobile/15E148 MicroMessenger/8.0.20(0x1800142f) NetType/WIFI Language/zh_CN",
|
|
|
|
"content-type": "application/json",
|
|
|
|
}
|
2023-10-19 13:55:12 +00:00
|
|
|
|
|
|
|
# This should not be there
|
2023-03-07 13:29:24 +00:00
|
|
|
VERSION = "3.5"
|
2022-12-10 12:37:43 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.client = httpx.AsyncClient(headers=self.HEADERS)
|
|
|
|
self.time = 0
|
|
|
|
self.data = None
|
|
|
|
self.ttl = 10 * 60
|
|
|
|
|
2023-10-19 13:55:12 +00:00
|
|
|
async def get_data(self) -> List[Dict[str, Dict]]:
|
2022-12-10 12:37:43 +00:00
|
|
|
if self.data is None or self.time + self.ttl < time.time():
|
2023-10-19 13:55:12 +00:00
|
|
|
data = await self.client.get(self.TEAM_RATE_API)
|
|
|
|
data_json = data.json()["data"]
|
|
|
|
self.data = data_json
|
2022-12-10 12:37:43 +00:00
|
|
|
self.time = time.time()
|
2023-10-19 13:55:12 +00:00
|
|
|
return self.data.copy()
|
2022-12-10 12:37:43 +00:00
|
|
|
|
|
|
|
async def close(self):
|
|
|
|
await self.client.aclose()
|