Just merge all the CSS into one
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 16s

This commit is contained in:
Nexus 2024-05-03 19:14:33 +01:00
parent 0ff3de0ea4
commit 16bd14bdc1
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -49,7 +49,7 @@ class ElectionCog(commands.Cog):
if not good_soup: if not good_soup:
return 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: def find_colour(style_name: str, want: str = "background-colour") -> str | None:
index = css.index(style_name) + len(style_name) + 1 index = css.index(style_name) + len(style_name) + 1
@ -58,13 +58,13 @@ class ElectionCog(commands.Cog):
if char == "}": if char == "}":
break break
value += char value += char
attributes = filter(value.split(";")) attributes = filter(None, value.split(";"))
parsed = {} parsed = {}
for attr in attributes: for attr in attributes:
name, val = attr.split(":") name, val = attr.split(":")
parsed[name] = val parsed[name] = val
if want in parsed: if want in parsed:
return parsed[name] return parsed[want]
results: dict[str, list[int]] = {} results: dict[str, list[int]] = {}
for child_ul in good_soup.children: for child_ul in good_soup.children:
@ -104,7 +104,7 @@ class ElectionCog(commands.Cog):
) )
# noinspection PyTypeChecker # 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) results = await self.bot.loop.run_in_executor(None, self.process_soup, soup)
if results: if results:
date = ctx.message.created_at.date().strftime("%B %Y") date = ctx.message.created_at.date().strftime("%B %Y")