refactor texts to settings, include undefined

matrix
Clemens Klug 2018-03-07 09:57:24 +01:00
parent 4631ed96f6
commit a1d3672357
2 changed files with 9 additions and 8 deletions

12
bot.py
View File

@ -19,12 +19,8 @@ def get_status():
status["timestamp"] = parse_time(status['timestamp']) status["timestamp"] = parse_time(status['timestamp'])
return status return status
def get_status_text(src=get_status): def get_status_text(config, src=get_status):
if get_status()["doorstate"]: return config["texts"][str(get_status()["doorstate"])]
text = "fs WIAI is open :)"
else:
text = "fs WIAI is closed :("
return text
def post(chats, text, token): def post(chats, text, token):
url = "https://api.telegram.org/bot{token}/sendMessage".format(token=token) url = "https://api.telegram.org/bot{token}/sendMessage".format(token=token)
@ -35,7 +31,7 @@ def post(chats, text, token):
def main(args={"config": "settings.json"}): def main(args={"config": "settings.json"}):
log.info("run once") log.info("run once")
config = json.load(open(args['config'])) config = json.load(open(args['config']))
text = get_status_text() text = get_status_text(config)
post(config['groups'], text, config['token']) post(config['groups'], text, config['token'])
post_plot(config) post_plot(config)
@ -62,7 +58,7 @@ def do_loop(config):
changed = True changed = True
if changed: if changed:
last_state = new_state 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"]) post(config["groups"], text, config["token"])
log.info("run pending tasks") log.info("run pending tasks")
schedule.run_pending() schedule.run_pending()

View File

@ -9,5 +9,10 @@
"WIAIdoorTest": -234502, "WIAIdoorTest": -234502,
"name": -1333, "name": -1333,
"fswiai main": -1001 "fswiai main": -1001
},
"texts":{
"-1": "fs WIAI is undefined ¯\_(ツ)_/¯",
"0": "fs WIAI is closed :(",
"1": "fs WIAI is open :)"
} }
} }