move functions to nive places

matrix
agp8x 2018-04-11 22:09:38 +02:00
parent 4b962c4bb5
commit e624296fd2
1 changed files with 9 additions and 9 deletions

18
bot.py
View File

@ -21,6 +21,12 @@ def publish(clients, fn, **kwargs):
for client in clients:
fn(client, **kwargs)
def post_plot(config):
with NamedTemporaryFile() as target:
plot_file, last = get_plot(target)
plot_file.seek(0)
publish(config.clients, Client.post_image, file=plot_file, name="")
def has_argument(args, key):
return key in args and args[key]
@ -38,6 +44,9 @@ def get_config(args):
loop=args['loop'])
return config
def setup(config):
schedule.every(config.plot_interval).seconds.do(lambda: post_plot(config))
def main(args={'config': "settings.json"}):
config = get_config(args)
@ -58,15 +67,6 @@ def main(args={'config': "settings.json"}):
if not config.loop:
post_plot(config)
def post_plot(config):
with NamedTemporaryFile() as target:
plot_file, last = get_plot(target)
plot_file.seek(0)
publish(config.clients, Client.post_image, file=plot_file, name="")
def setup(config):
schedule.every(config.plot_interval).seconds.do(lambda: post_plot(config))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="DoorStateBot")
parser.add_argument("--config", "-c", default="settings.json", help="Configuration file")