diff options
Diffstat (limited to 'single_shot.py')
| -rwxr-xr-x | single_shot.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/single_shot.py b/single_shot.py index 41d9849..0c85947 100755 --- a/single_shot.py +++ b/single_shot.py @@ -80,24 +80,23 @@ def main(): if not group_id: die('A group id must be provided') - bot = Geldschieberbot(state_path, group_id, dry_run=args.dry_run) - - # Read cmds from stdin - for line in sys.stdin.read().splitlines(): - try: - envelope = json.loads(line)['envelope'] - except json.JSONDecodeError: - print(datetime.now(), line, "not valid json") - continue - - quote = None - if not args.no_quote: - quote = Quote(timestamp=envelope['timestamp'], - author=envelope['source']) - - send(send_cmd, bot.handle(envelope), quote) - - send(send_cmd, bot.run_scheduled_cmds()) + with Geldschieberbot(state_path, group_id, dry_run=args.dry_run) as bot: + # Read cmds from stdin + for line in sys.stdin.read().splitlines(): + try: + envelope = json.loads(line)['envelope'] + except json.JSONDecodeError: + print(datetime.now(), line, "not valid json") + continue + + quote = None + if not args.no_quote: + quote = Quote(timestamp=envelope['timestamp'], + author=envelope['source']) + + send(send_cmd, bot.handle(envelope), quote) + + send(send_cmd, bot.run_scheduled_cmds()) if __name__ == "__main__": |
