From 85d6a3a54f717e9431212e539f3ab1a133444def Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sun, 15 Oct 2023 17:50:05 -0700 Subject: [PATCH] Fixes #1 Adding event organizer to the /trackdays blurb and also fixing it so if an org only has one day, it will still show up --- app/cogs/actual_utils.py | 7 ++++++- app/trackdays.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index ab4d1e0f..ef2b0546 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -132,7 +132,12 @@ class ActualUtils(commands.Cog): ) for track_day in events: embed.add_field( - name="-------------\n**Event Name**", + name="-------------\n**Organizer**", + value=track_day["event_organizer"], + inline=False, + ) + embed.add_field( + name="**Event Name**", value=track_day["event_name"], inline=False, ) diff --git a/app/trackdays.py b/app/trackdays.py index 7562df07..a2b2f6c7 100755 --- a/app/trackdays.py +++ b/app/trackdays.py @@ -13,7 +13,6 @@ async def get_msreg(track): "turn8": "F3469266-BEFF-E329-4FD6C4B189ACE2A8", "speedventures": "DF7453ED-BF33-DC17-2C9BFD84C1F05E86", "nextlevel": "CC23AEA4-AAB1-D087-4A10818D229DAFD2", - "corsaclub": "CE6E69CF-BAEC-DBB6-303EE7D3EC69B8A3", "lightspeed": "BC6417B8-0ED9-DD48-28BA1463C2C14322", "socaldriversclub": "B4FC0113-C903-E9D3-68562D6765806945", } @@ -35,10 +34,16 @@ async def get_msreg(track): json.dumps(xmltodict.parse(awaited_xml_blob)["response"]["events"]) ) + # If an organizer only has one upcoming event on MSReg, it is a dict, otherwise its a list of dicts + # My code assumes list of dicts, so wrap the event dict in a list of 1 item + if json_blob and isinstance(json_blob["event"], dict): + json_blob["event"] = [json_blob["event"]] + try: for event in json_blob["event"]: if any(x in event["name"].lower() for x in tracks_we_care_about): event_object = { + "event_organizer": event["organization"]["name"], "event_name": event["name"], "event_url": event["detailuri"].split("?utm")[0], "event_date": event["start"], @@ -55,7 +60,9 @@ async def get_msreg(track): ), ) - except TypeError: + except Exception as e: + print("Errored on %s" % org_name) + print(e) pass return events @@ -68,7 +75,6 @@ def get_corsa_club(): for event in products_blob: # Filter out hoodies and what not, only care about track days that list run-groups as the options if any("Intermediate" in s for s in event["options"][0]["values"]): - # pp.pprint(event) event_object = { "event_name": event["title"], "event_url": base_url + "/products/" + event["handle"],