From df11aef895e1681531f4876ec3eeaa0f44c80c91 Mon Sep 17 00:00:00 2001 From: agp8x Date: Wed, 11 Apr 2018 19:16:59 +0200 Subject: [PATCH] load text from config --- bot.py | 9 +++++---- settings.sample.json | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index f17810f..107525a 100644 --- a/bot.py +++ b/bot.py @@ -19,7 +19,8 @@ def get_status(): status["timestamp"] = parse_time(status['timestamp']) return status -def get_status_text(src=get_status): +def get_status_text(config, src=get_status): + return config["texts"][str(get_status()["doorstate"])] if get_status()["doorstate"]: text = "fs WIAI is open :)" else: @@ -35,9 +36,9 @@ def post(chats, text, token): def main(args={"config": "settings.json"}): log.info("run once") config = json.load(open(args['config'])) - text = get_status_text() + text = get_status_text(config) post(config['groups'], text, config['token']) - post_plot(config) + #post_plot(config) def loop(args={"config": "settings.json"}): log.info("prepare loop") @@ -62,7 +63,7 @@ def do_loop(config): changed = True if changed: last_state = new_state - text = get_status_text(lambda: last_state) + text = get_status_text(config, lambda: last_state) post(config["groups"], text, config["token"]) log.info("run pending tasks") schedule.run_pending() diff --git a/settings.sample.json b/settings.sample.json index d57280e..beed094 100644 --- a/settings.sample.json +++ b/settings.sample.json @@ -9,5 +9,10 @@ "WIAIdoorTest": -234502, "name": -1333, "fswiai main": -1001 + }, + "texts":{ + "-1": "fs WIAI is undefined ¯\_(ツ)_/¯", + "0": "fs WIAI is closed :(", + "1": "fs WIAI is open :)" } }