refactor texts to settings, include undefined
parent
4631ed96f6
commit
a1d3672357
12
bot.py
12
bot.py
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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 :)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue