From 0e9859f8a04c1bc4b80412ea82dedbba1ca5df14 Mon Sep 17 00:00:00 2001 From: Jiri Vlasak Date: Wed, 20 Mar 2019 10:24:19 +0100 Subject: [PATCH] Add config module This module retrieves configuration. --- .cfg | 8 ++++++++ cbconf.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .cfg create mode 100644 cbconf.py diff --git a/.cfg b/.cfg new file mode 100644 index 0000000..a287dba --- /dev/null +++ b/.cfg @@ -0,0 +1,8 @@ +{ + "coffeebot": { + "url": "https://hooks.slack.com/services/..." + }, + "coffeedb": { + "path": "./coffee.db" + } +} diff --git a/cbconf.py b/cbconf.py new file mode 100644 index 0000000..69d53e3 --- /dev/null +++ b/cbconf.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +"""Get configuration.""" +from json import loads + +class Conf: + PATH = ".cfg" + + def __init__(self): + with open(Conf.PATH) as f: + self.conf = loads(f.read()) + return None + + def getCoffeebotURL(self): + """Return URL of Slack Coffeebot.""" + return self.conf["coffeebot"]["url"] + + def getCoffeeDbPath(self): + """Return the path to database with coffees.""" + return self.conf["coffeedb"]["path"] -- 2.39.2