From 0874ad78e0eb17d72641ee14957dc4ae5ecd792a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 5 Jul 2024 00:42:12 +0100 Subject: [PATCH] Include 2019 in counts --- src/cogs/election.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cogs/election.py b/src/cogs/election.py index be1476a..44b0c3f 100644 --- a/src/cogs/election.py +++ b/src/cogs/election.py @@ -127,7 +127,7 @@ class ElectionCog(commands.Cog): except ValueError: self.log.error("failed to parse %r", span) continue - results[party] = [seats, change, 0] + results[party] = [seats, change, 0, 0] # if not span: # self.log.warning("%r did not have a 'span' element.", child_ul) # continue @@ -148,6 +148,17 @@ class ElectionCog(commands.Cog): # int(groups["net"].strip()) * MULTI[groups["net_change"]], # int(find_colour(child_ul.next["class"][0])[1:], base=16) # ] + for child_li in good_soups[1].children: + span = list(child_li.children)[-1] + try: + party, extra = span.get_text().strip().split(":", 1) + seats, _ = extra.split(" ", 1) + seats = int(seats) + except ValueError: + self.log.error("failed to parse %r", span) + continue + if party in results: + results[party][3] = seats return results async def _get_embed(self) -> discord.Embed | None: @@ -170,11 +181,11 @@ class ElectionCog(commands.Cog): description_parts = [] for party_name, values in results.items(): - councillors, net, colour = values + councillors, net, colour, last_election = values colour_scores[party_name] = councillors symbol = "+" if net > 0 else '' description_parts.append( - f"**{party_name}**: {symbol}{net:,} ({councillors:,} total)" + f"**{party_name}**: {symbol}{net:,} ({councillors:,} total, {last_election:,} in 2019)" ) top_party = list(sorted(colour_scores.keys(), key=lambda k: colour_scores[k], reverse=True))[0]