From e624296fd2eb37f9e6265a45781ead0a9fea14e9 Mon Sep 17 00:00:00 2001 From: agp8x Date: Wed, 11 Apr 2018 22:09:38 +0200 Subject: [PATCH] move functions to nive places --- bot.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index 801f241..685556d 100644 --- a/bot.py +++ b/bot.py @@ -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")