mirror of
https://github.com/PaiGramTeam/Gift-Code-Web.git
synced 2024-11-25 01:21:59 +00:00
🐛 Fix honkai web parse
This commit is contained in:
parent
7b19618fcd
commit
a383146114
@ -20,6 +20,7 @@ reward_map = {
|
|||||||
"Dust of Alacrity": "疾速粉尘",
|
"Dust of Alacrity": "疾速粉尘",
|
||||||
"Condensed Aether": "凝缩以太",
|
"Condensed Aether": "凝缩以太",
|
||||||
"Cosmic Fried Rice": "大宇宙炒饭",
|
"Cosmic Fried Rice": "大宇宙炒饭",
|
||||||
|
"Travel Encounters": "旅情见闻",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,25 +45,18 @@ def parse_code(tr: Tag) -> Code:
|
|||||||
tds = tr.find_all("td")
|
tds = tr.find_all("td")
|
||||||
code = tds[0].text.strip()
|
code = tds[0].text.strip()
|
||||||
try:
|
try:
|
||||||
expire = tds[2].text.strip()
|
_, expire = str(tds[2]).split("<br/>")
|
||||||
except IndexError:
|
except (IndexError, TypeError):
|
||||||
expire = datetime(1970, 1, 1, 1, 0, 0, 0)
|
_, expire = datetime(1970, 1, 1, 1, 0, 0, 0), datetime(2099, 12, 31, 23, 59, 59, 999999)
|
||||||
if isinstance(expire, str):
|
if isinstance(expire, str):
|
||||||
if expire.endswith("?"):
|
try:
|
||||||
|
expire = expire.split(": ")[1].replace("</td>", "")
|
||||||
|
if expire == "Unknown":
|
||||||
expire = datetime(2099, 12, 31, 23, 59, 59, 999999)
|
expire = datetime(2099, 12, 31, 23, 59, 59, 999999)
|
||||||
else:
|
else:
|
||||||
expires = expire.split(" – ")
|
expire = datetime.strptime(expire, "%B %d, %Y")
|
||||||
day = expires[1].split(" ")[-1]
|
except IndexError:
|
||||||
month = expires[0].split(" ")[0]
|
expire = datetime(2099, 12, 31, 23, 59, 59, 999999)
|
||||||
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 = timezone("Asia/Shanghai").localize(expire)
|
||||||
expire = int(expire.timestamp() * 1000)
|
expire = int(expire.timestamp() * 1000)
|
||||||
rewards = []
|
rewards = []
|
||||||
|
Loading…
Reference in New Issue
Block a user