From 1a629426a7518df54ad5ec2535fd0af55e71caa6 Mon Sep 17 00:00:00 2001 From: electrorayer Date: Sun, 23 Apr 2023 15:22:20 +0200 Subject: [PATCH] extra checks --- .gitignore | 3 ++- electrobot.py | 5 ++++- predictions.py | 2 +- predictions/predictions.json | 15 ++++++--------- predictions_manager.py | 32 ++++++++++++++++++++++---------- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 9fdca90..f50cd92 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ config/config.toml tokens/ logs/ test.py -test2.py \ No newline at end of file +test2.py +predictions/ \ No newline at end of file diff --git a/electrobot.py b/electrobot.py index 5a84579..b84eac2 100644 --- a/electrobot.py +++ b/electrobot.py @@ -274,7 +274,10 @@ def read_data(): elif msg[1] == "PRIVMSG": #TODO commands, modcommands, song, pb, wr chat_interact(buffer.splitlines(), mods) except ssl.SSLWantReadError: #timeout - continue + continue + except KeyboardInterrupt: + LOG.logger.info("Closing bot...") + break except Exception: LOG.logger.error("Exception in read_data", exc_info=True) diff --git a/predictions.py b/predictions.py index a05f0f4..3dbd720 100644 --- a/predictions.py +++ b/predictions.py @@ -48,7 +48,7 @@ def get_self_starting_predictions(): auto_predictions = [] #auto start based on current split for p in data['predictions']: - if p['auto_predict']['auto_start'] == True: + if p['auto_predict']['auto_start']: auto_pred = { "name": p['name'], "split_name": p['auto_predict']['split_name'] diff --git a/predictions/predictions.json b/predictions/predictions.json index c3afcf5..1ec0add 100644 --- a/predictions/predictions.json +++ b/predictions/predictions.json @@ -2,26 +2,23 @@ "predictions": [ { "auto_predict": { - "auto_start": false, - "split_name": "" + "auto_start": true, + "split_name": "repo" }, "data": { "broadcaster_id": "", "outcomes": [ { - "title": "Yes" + "title": "yes" }, { - "title": "No" - }, - { - "title": "Maybe" + "title": "no" } ], "prediction_window": 600, - "title": "Is this an example?" + "title": "is something?" }, - "name": "example" + "name": "repo" } ] } \ No newline at end of file diff --git a/predictions_manager.py b/predictions_manager.py index 6436d02..905ecd8 100644 --- a/predictions_manager.py +++ b/predictions_manager.py @@ -1,10 +1,22 @@ import tkinter as tk import json +import os +if not os.path.exists('predictions'): + os.makedirs('predictions') -with open('predictions/predictions.json', 'r') as file: - dict = json.load(file) +while 1: + try: + with open('predictions/predictions.json', 'r') as file: + dict = json.load(file) + break + except FileNotFoundError: + default_content = { + "predictions": [] + } + with open('predictions/predictions.json', 'w') as file: + file.write(json.dumps(default_content)) def handle_select_pred(event): @@ -87,14 +99,6 @@ def handle_save(): lbl_error.config(text="Saved changes", fg="green") -def refresh_list(): - #erase, write - lb_list.delete(0, tk.END) - - for i, pred in enumerate(dict['predictions']): - lb_list.insert(i, pred['name']) - - def handle_delete(): delete_name = ent_name.get() @@ -109,6 +113,14 @@ def handle_delete(): refresh_list() +def refresh_list(): + #erase, write + lb_list.delete(0, tk.END) + + for i, pred in enumerate(dict['predictions']): + lb_list.insert(i, pred['name']) + + def validate_form(): try: lbl_error.config(text="", fg="red")