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
This commit is contained in:
Tony Breeds 2023-10-04 09:54:11 +11:00
parent 0954e95fdc
commit d01468e188

View File

@ -4,7 +4,9 @@ import icalendar
def json2ical(db, include_teams="ALL"): def json2ical(db, include_teams="ALL"):
teams = slots = {} teams = {}
slots = {}
eventid = db["eventid"]
# FIXME: The unused label and the _slots here are irritating. # FIXME: The unused label and the _slots here are irritating.
for label, _slots in db["slots"].items(): for label, _slots in db["slots"].items():
@ -30,10 +32,12 @@ def json2ical(db, include_teams="ALL"):
c.add("version", "2.0") c.add("version", "2.0")
for team in include_teams: for team in include_teams:
default_etherpad = f"https://etherpad.opendev.org/p/{eventid}-{team}"
for booking in teams.get(team, []): for booking in teams.get(team, []):
location, slot = booking location, slot = booking
url = db["schedule"].get(location, {}).get("url", "") url = (db["urls"].get(team) or
etherpad = db["etherpads"].get(team, "") db["schedule"].get(location, {}).get("url", ""))
etherpad = db["etherpads"].get(team, default_etherpad)
time = slots.get(slot, {}).get("realtime") time = slots.get(slot, {}).get("realtime")
# TODO(tonyb): 60 mins is a default picked to make the existing # TODO(tonyb): 60 mins is a default picked to make the existing
# DB work unchanged. We can leave this as is or pick another # 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("summary", summary)
e.add("description", desc) e.add("description", desc)
e.add("dtstart", dtstart) e.add("dtstart", dtstart)
e.add("dtend", dtstart + datetime.timedelta(mins=duration)) e.add("dtend", dtstart + datetime.timedelta(minutes=duration))
e.add("priority", 0) e.add("priority", 0)
e.add("uid", uid)
# FIXME: Why the change in format e.add("location", icalendar.vText(url))
# 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
c.add_component(e) c.add_component(e)