From d01468e1880d294abd82ab65ca50a6b419f758d8 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Wed, 4 Oct 2023 09:54:11 +1100 Subject: [PATCH] Fix errors in iCal There were several issues with generating the ptg.ics. Errors causing python tracebacks: 1. teams = slots = {} This was a gotcha for me. This essentially makes teams and slots aliases for the *same* empty dictionary. Not as I thought creating creating 2 empty dictionaries. Upon reflection it is obvious. This meant that I was treating a "slot code" [MonA1] as a track/team 2. datetime.timedelta()'s keyword is "minutes" not "mins" Functional errors: 1. If a team/track sets a VC url, it goes into db["urls"]. Look there first and if not there look for a URL from the slot/room location. 2. Use a reasonable isn't a team/track key in db["etherpads"]. Non-functional changes: 1. There were a couple of FIXMEs which were addressed. e["key"] = "value" is the same as e.add("key", "value") 2. An empty url (""), is fine to add into the location, just strange. Change-Id: I458924bfc26c47f4e062cc16f48e2d72da361918 --- ptgbot/ics.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ptgbot/ics.py b/ptgbot/ics.py index 370486f..def6029 100644 --- a/ptgbot/ics.py +++ b/ptgbot/ics.py @@ -4,7 +4,9 @@ import icalendar def json2ical(db, include_teams="ALL"): - teams = slots = {} + teams = {} + slots = {} + eventid = db["eventid"] # FIXME: The unused label and the _slots here are irritating. for label, _slots in db["slots"].items(): @@ -30,10 +32,12 @@ def json2ical(db, include_teams="ALL"): c.add("version", "2.0") for team in include_teams: + default_etherpad = f"https://etherpad.opendev.org/p/{eventid}-{team}" for booking in teams.get(team, []): location, slot = booking - url = db["schedule"].get(location, {}).get("url", "") - etherpad = db["etherpads"].get(team, "") + url = (db["urls"].get(team) or + db["schedule"].get(location, {}).get("url", "")) + etherpad = db["etherpads"].get(team, default_etherpad) time = slots.get(slot, {}).get("realtime") # TODO(tonyb): 60 mins is a default picked to make the existing # DB work unchanged. We can leave this as is or pick another @@ -52,14 +56,10 @@ def json2ical(db, include_teams="ALL"): e.add("summary", summary) e.add("description", desc) e.add("dtstart", dtstart) - e.add("dtend", dtstart + datetime.timedelta(mins=duration)) + e.add("dtend", dtstart + datetime.timedelta(minutes=duration)) e.add("priority", 0) - - # FIXME: Why the change in format - # FIXME: Check for empty url? it shouldn't happen due to the - # way we build the the teams/bookings lists - e["location"] = icalendar.vText(url) - e["uid"] = uid + e.add("uid", uid) + e.add("location", icalendar.vText(url)) c.add_component(e)