move functions to nive places
parent
4b962c4bb5
commit
e624296fd2
18
bot.py
18
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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue