Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复赛马娘重载卡池失败的问题 #969

Merged
merged 3 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/draw_card/handles/base_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class UpEvent(BaseModel):
start_time: Optional[datetime] # 开始时间
end_time: Optional[datetime] # 结束时间
up_char: List[UpChar] # up对象
up_name: str = "" # up名称


TC = TypeVar("TC", bound="BaseData")
Expand Down
27 changes: 17 additions & 10 deletions plugins/draw_card/handles/pretty_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,48 +350,52 @@ async def update_up_char(self):
char_img = ""
card_img = ""
up_chars = []
up_chars_name = []
up_cards = []
up_cards_name = []
soup = BeautifulSoup(result, "lxml")
heads = soup.find_all("span", {"class": "mw-headline"})
for head in heads:
if "时间" in head.text:
if "时间" in head.text or "期间" in head.text:
time = head.find_next("p").text.split("\n")[0]
if "~" in time:
start, end = time.split("~")
start_time = dateparser.parse(start)
end_time = dateparser.parse(end)
elif "赛马娘" in head.text:
char_img = head.find_next("a", {"class": "image"}).find("img")[
char_img = head.find_next("center").find("img")[
"src"
]
lines = str(head.find_next("p").text).split("\n")
chars = [
line
for line in lines
if "★" in line and "" in line and "" in line
if "★" in line and "" in line and "" in line
]
for char in chars:
for char in set(chars): # list去重
star = char.count("★")
name = re.split(r"[()]", char)[-2].strip()
name = re.split(r"[【】]", char)[-2].strip()
up_chars.append(
UpChar(name=name, star=star, limited=False, zoom=70)
)
up_chars_name.append(name)
elif "支援卡" in head.text:
card_img = head.find_next("a", {"class": "image"}).find("img")[
card_img = head.find_next("center").find("img")[
"src"
]
lines = str(head.find_next("p").text).split("\n")
cards = [
line
for line in lines
if "R" in line and "" in line and "" in line
if "R" in line and "" in line and "" in line
]
for card in cards:
star = 3 if "SSR" in card else 2 if "SR" in card else 1
name = re.split(r"[()]", card)[-2].strip()
name = re.split(r"[【】]", card)[-2].strip()
up_cards.append(
UpChar(name=name, star=star, limited=False, zoom=70)
)
up_cards_name.append(name)
if start_time and end_time:
if start_time <= datetime.now() <= end_time:
self.UP_CHAR = UpEvent(
Expand All @@ -400,13 +404,15 @@ async def update_up_char(self):
start_time=start_time,
end_time=end_time,
up_char=up_chars,
up_name=up_chars_name,
)
self.UP_CARD = UpEvent(
title=title,
pool_img=card_img,
start_time=start_time,
end_time=end_time,
up_char=up_cards,
up_name=up_cards_name,
)
self.dump_up_char()
logger.info(f"成功获取{self.game_name_cn}当前up信息...当前up池: {title}")
Expand All @@ -418,9 +424,10 @@ async def _reload_pool(self) -> Optional[Message]:
self.load_up_char()
if self.UP_CHAR and self.UP_CARD:
return Message(
Message.template("重载成功!\n当前UP池子:{}{:image}{:image}").format(
self.UP_CHAR.title,
Message.template("重载成功!\n当前UP池子:{}{:image}\n当前支援卡池子:{}{:image}").format(
self.UP_CHAR.up_name,
self.UP_CHAR.pool_img,
self.UP_CARD.up_name,
self.UP_CARD.pool_img,
)
)