Add scheduled / additional rooms
Allow to configure a schedule for scheduled rooms and a number of available time slots in additional rooms. Change-Id: Ibb4650cc73c08dc5c4328a8a844ed54fac991f84
This commit is contained in:
parent
2ddba00d6d
commit
e9e50b0b1b
|
@ -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"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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', ''),
|
||||
|
|
26
ptgbot/db.py
26
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):
|
||||
|
|
Loading…
Reference in New Issue