diff --git a/config.json.sample b/config.json.sample index bc7a17b..f42c082 100644 --- a/config.json.sample +++ b/config.json.sample @@ -4,5 +4,27 @@ "irc_server": "irc.freenode.net", "irc_port": 6667, "irc_channel": "#CHANNEL", - "db_filename": "html/ptg.json" + "db_filename": "html/ptg.json", + "slots": { + "Monday": [ + { + "name": "MonAM", + "desc": "09:00-12:00" + }, + { + "name": "MonPM", + "desc": "14:00-17:00" + } + ], + "Tuesday": [ + { + "name": "TueAM", + "desc": "09:00-12:00" + }, + { + "name": "TuePM", + "desc": "14:00-17:00" + } + ] + } } diff --git a/ptgbot/bot.py b/ptgbot/bot.py index b7e9583..7db1876 100644 --- a/ptgbot/bot.py +++ b/ptgbot/bot.py @@ -16,6 +16,7 @@ # limitations under the License. import argparse +import collections import daemon import irc.bot import json @@ -171,7 +172,7 @@ class PTGBot(irc.bot.SingleServerIRCBot): def start(configpath): with open(configpath, 'r') as fp: - config = json.load(fp) + config = json.load(fp, object_pairs_hook=collections.OrderedDict) if 'log_config' in config: log_config = config['log_config'] @@ -182,7 +183,7 @@ def start(configpath): else: logging.basicConfig(level=logging.DEBUG) - db = ptgbot.db.PTGDataBase(config['db_filename']) + db = ptgbot.db.PTGDataBase(config['db_filename'], config['slots']) bot = PTGBot(config['irc_nick'], config.get('irc_pass', ''), diff --git a/ptgbot/db.py b/ptgbot/db.py index c437126..b814154 100644 --- a/ptgbot/db.py +++ b/ptgbot/db.py @@ -21,16 +21,17 @@ import datetime class PTGDataBase(): - BASE = {'tracks': [], 'now': {}, 'next': {}, 'colors': {}, + BASE = {'tracks': [], 'slots': {}, 'now': {}, 'next': {}, 'colors': {}, 'location': {}} - def __init__(self, filename): + def __init__(self, filename, slots): self.filename = filename if os.path.isfile(filename): with open(filename, 'r') as fp: self.data = json.load(fp) else: self.data = self.BASE + self.data['slots'] = slots self.save() def add_now(self, track, session):