From d57f89dcb9f648b33758dec74ff25af2d27e6586 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Fri, 22 Dec 2017 16:44:24 +0100 Subject: [PATCH] Also find room for tracks in additional rooms The get_track_room function failed to also look in additional rooms to find the room for a given track. If the event is not running in the current day, we should default to the first day of the event (useful for tests and the day before the event starts). Change-Id: I143eb3b490b3536679e0608064209ec71ed37499 --- ptgbot/db.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ptgbot/db.py b/ptgbot/db.py index 1541175..1b75e53 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -15,6 +15,7 @@ # limitations under the License. import calendar +from itertools import chain import json import os import datetime @@ -73,9 +74,14 @@ class PTGDataBase(): def get_track_room(self, track): # This simplified version returns the first room the track is - # scheduled in for the day + # scheduled in for the day. If the event does not run on this + # day, pick the first day. today = calendar.day_name[datetime.date.today().weekday()] - for room, bookings in self.data['scheduled'].items(): + if today not in self.data['slots']: + today = next(iter(self.data['slots'])) + all_schedule = chain(self.data['scheduled'].items(), + self.data['additional'].items()) + for room, bookings in all_schedule: for btime, btrack in bookings.items(): for slot in self.data['slots'].get(today, []): if btrack == track and btime == slot['name']: