From d4660208d28af6281e8a7c6fab34e2fbcaa93ffa Mon Sep 17 00:00:00 2001 From: Andrea Cornell Date: Tue, 1 Nov 2022 21:46:34 -0400 Subject: [PATCH] sidebot: catch up strikebot_updates.py --- sidebot/sidebot/strikebot_updates.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sidebot/sidebot/strikebot_updates.py b/sidebot/sidebot/strikebot_updates.py index 6e072db..6c90e5f 100644 --- a/sidebot/sidebot/strikebot_updates.py +++ b/sidebot/sidebot/strikebot_updates.py @@ -37,7 +37,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) - # flatten the update content to plain text tree = BeautifulSoup(payload_data["body_html"], "html.parser") - worklist = tree.contents + worklist = list(reversed(tree.contents)) out = [[]] while worklist: el = worklist.pop() @@ -45,7 +45,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) - out[-1].append(el) elif el is SPACE: out[-1].append(el) - elif el is NEW_LINE or el.name == "br" or el.name == "hr": + elif el is NEW_LINE or el.name in ["br", "hr"]: if out[-1]: out.append([]) elif el.name in ["em", "strong", "del", "span", "sup", "code", "a", "th", "td"]: @@ -88,7 +88,7 @@ def parse_update(payload_data: dict, curr_count: Optional[int], bot_user: str) - def _parse_from_lines(lines: list[str], curr_count: Optional[int], bot_user: str) -> ParsedUpdate: command = next( - filter(None, (_parse_command(l, bot_user) for l in lines)), + (cmd for l in lines if (cmd := _parse_command(l, bot_user))), None ) if lines: @@ -136,7 +136,7 @@ def _parse_from_lines(lines: list[str], curr_count: Optional[int], bot_user: str if parts in partials: # missing any of last two digits typo = True - elif parts in [p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials]: + elif any(parts == p[: -1] + [p[-1] + goal_parts[0]] + goal_parts[1 :] for p in partials): # double paste typo = True -- 2.30.2