diff --git a/config.json.sample b/config.json.sample index f42c082..89ed1b9 100644 --- a/config.json.sample +++ b/config.json.sample @@ -26,5 +26,22 @@ "desc": "14:00-17:00" } ] + }, + "scheduled": { + "Ontario": { + "MonAM": "swift", + "MonPM": "swift", + "TueAM": "swift", + "TuePM": "swift" + }, + "Montana": { + "MonAM": "cinder", + "MonPM": "cinder", + "TueAM": "cinder", + "TuePM": "cinder" + } + }, + "extrarooms": { + "Missouri": ["MonAM", "MonPM", "TueAM", "TuePM"] } } diff --git a/ptgbot/bot.py b/ptgbot/bot.py index 7db1876..6ae7a34 100644 --- a/ptgbot/bot.py +++ b/ptgbot/bot.py @@ -183,7 +183,10 @@ def start(configpath): else: logging.basicConfig(level=logging.DEBUG) - db = ptgbot.db.PTGDataBase(config['db_filename'], config['slots']) + db = ptgbot.db.PTGDataBase(config['db_filename'], + config['slots'], + config['scheduled'], + config['extrarooms']) bot = PTGBot(config['irc_nick'], config.get('irc_pass', ''), diff --git a/ptgbot/db.py b/ptgbot/db.py index b814154..bb3bf7f 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -22,9 +22,9 @@ import datetime class PTGDataBase(): BASE = {'tracks': [], 'slots': {}, 'now': {}, 'next': {}, 'colors': {}, - 'location': {}} + 'location': {}, 'scheduled': {}, 'additional': {}} - def __init__(self, filename, slots): + def __init__(self, filename, slots, scheduled, extrarooms): self.filename = filename if os.path.isfile(filename): with open(filename, 'r') as fp: @@ -32,6 +32,28 @@ class PTGDataBase(): else: self.data = self.BASE self.data['slots'] = slots + + self.data['scheduled'] = scheduled + # Add tracks mentioned in configuration that are not in track list + for room, bookings in scheduled.items(): + for time, track in bookings.items(): + if track not in self.data['tracks']: + self.data['tracks'].append(track) + + # Rebuild 'additional' with rooms and slots from configuration, but + # use saved data where the room/slot is preserved + old_data = self.data['additional'].copy() + self.data['additional'] = {} + + for room in extrarooms.keys(): + self.data['additional'][room] = {} + for slot in extrarooms[room]: + try: + self.data['additional'][room][slot] = old_data[room][slot] + except KeyError: + self.data['additional'][room][slot] = '' + + # Save the data to disk self.save() def add_now(self, track, session):