diff --git a/src/cogs/election.py b/src/cogs/election.py index 7249c9b..5089ec6 100644 --- a/src/cogs/election.py +++ b/src/cogs/election.py @@ -49,7 +49,7 @@ class ElectionCog(commands.Cog): if not good_soup: return - css: str = [x for x in good_soup.find_all("style") if "Results" in x.get_text()][0].get_text() + css: str = "\n".join([x.get_text() for x in good_soup.find_all("style") if "Results" in x.get_text()]) def find_colour(style_name: str, want: str = "background-colour") -> str | None: index = css.index(style_name) + len(style_name) + 1 @@ -58,13 +58,13 @@ class ElectionCog(commands.Cog): if char == "}": break value += char - attributes = filter(value.split(";")) + attributes = filter(None, value.split(";")) parsed = {} for attr in attributes: name, val = attr.split(":") parsed[name] = val if want in parsed: - return parsed[name] + return parsed[want] results: dict[str, list[int]] = {} for child_ul in good_soup.children: @@ -104,7 +104,7 @@ class ElectionCog(commands.Cog): ) # noinspection PyTypeChecker - soup = await asyncio.to_thread(BeautifulSoup, response.text) + soup = await asyncio.to_thread(BeautifulSoup, response.text, "html.parser") results = await self.bot.loop.run_in_executor(None, self.process_soup, soup) if results: date = ctx.message.created_at.date().strftime("%B %Y")