mirror of
https://github.com/PaiGramTeam/Gift-Code-Web.git
synced 2024-11-24 00:21:36 +00:00
🐛 Fix honkai web parse
This commit is contained in:
parent
f21a6d6ae3
commit
7b19618fcd
@ -8,12 +8,13 @@ from bs4 import BeautifulSoup, Tag
|
||||
from .code import Code, Reward
|
||||
|
||||
|
||||
url = "https://honkai.gg/cn/codes"
|
||||
url = "https://honkai.gg/codes/"
|
||||
reward_map = {
|
||||
"Stellar Jade": "星琼",
|
||||
"Credit": "信用点",
|
||||
"Credits": "信用点",
|
||||
"Traveler's Guide": "漫游指南",
|
||||
"Traveler’s Guide": "漫游指南",
|
||||
"Refined Aether": "提纯以太",
|
||||
"Adventure Log": "冒险记录",
|
||||
"Dust of Alacrity": "疾速粉尘",
|
||||
@ -42,27 +43,32 @@ def parse_reward(reward: List[str]) -> Reward:
|
||||
def parse_code(tr: Tag) -> Code:
|
||||
tds = tr.find_all("td")
|
||||
code = tds[0].text.strip()
|
||||
expire = tds[2].text.strip()
|
||||
if expire.endswith("?"):
|
||||
expire = datetime(2099, 12, 31, 23, 59, 59, 999999)
|
||||
else:
|
||||
expires = expire.split(" - ")
|
||||
day = expires[1].split(" ")[-1]
|
||||
month = expires[0].split(" ")[0]
|
||||
try:
|
||||
if " " not in expires[1]:
|
||||
raise ValueError
|
||||
month = expires[1].split(" ")[0]
|
||||
except ValueError:
|
||||
pass
|
||||
now = datetime.now()
|
||||
expire = datetime.strptime(f"{day} {month}", "%d %b")
|
||||
expire = expire.replace(year=now.year, hour=23, minute=59, second=59, microsecond=999999)
|
||||
try:
|
||||
expire = tds[2].text.strip()
|
||||
except IndexError:
|
||||
expire = datetime(1970, 1, 1, 1, 0, 0, 0)
|
||||
if isinstance(expire, str):
|
||||
if expire.endswith("?"):
|
||||
expire = datetime(2099, 12, 31, 23, 59, 59, 999999)
|
||||
else:
|
||||
expires = expire.split(" – ")
|
||||
day = expires[1].split(" ")[-1]
|
||||
month = expires[0].split(" ")[0]
|
||||
try:
|
||||
if " " not in expires[1]:
|
||||
raise ValueError
|
||||
month = expires[1].split(" ")[0]
|
||||
except ValueError:
|
||||
pass
|
||||
now = datetime.now()
|
||||
expire = datetime.strptime(f"{day} {month}", "%d %b")
|
||||
expire = expire.replace(year=now.year, hour=23, minute=59, second=59, microsecond=999999)
|
||||
expire = timezone("Asia/Shanghai").localize(expire)
|
||||
expire = int(expire.timestamp() * 1000)
|
||||
rewards = []
|
||||
for reward in tds[1].find_all("div", {"class": "flex"}):
|
||||
reward_div = reward.text.strip().split("\xa0x ")
|
||||
for reward in str(tds[1]).split("<br/>"):
|
||||
reward = BeautifulSoup(reward, "lxml")
|
||||
reward_div = " ".join(reward.text.strip().split()).split(" x ")
|
||||
if len(reward_div) < 2:
|
||||
print("Bad td data: ", tds[1])
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user