From 4e939bec2f458035be0b85210581225a7f889e0e Mon Sep 17 00:00:00 2001 From: piair Date: Sun, 18 Jun 2023 18:32:06 +0200 Subject: [PATCH] YEAH --- Flask/app.py | 54 ++++++++++++++++++++++++++--------- Flask/templates/override.html | 4 +-- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Flask/app.py b/Flask/app.py index 1f0d31d..7f5bd65 100644 --- a/Flask/app.py +++ b/Flask/app.py @@ -28,19 +28,46 @@ if secret == "": scheduler = BackgroundScheduler() scheduler.start() -trigger = CronTrigger( - year="*", month="*", day="*", hour="2", minute="25", second="25" -) -def start_ms(): - subprocess.Popen(["python3", "./V6.py", "-v", "2345"]) +def start_ms(i): + print("\033[32m" + f"Starting config {i}" + "\033[0m") + subprocess.Popen(["python3", "./V6.py", "-c", i]) + -scheduler.add_job( - start_ms, - trigger=trigger, - #args=["hello world"], - name="Daily start", -) +TriggerDict = {} +def update_jobs(): + with open("./user_data/configs.json", "r") as inFile: + configs = json.load(inFile) + + for i in configs: + h, m = configs[i]["time"].split(":") + print("\033[36m" + f"config {i} : {h}:{m}" + "\033[0m") + TriggerDict[i] = CronTrigger( + year="*", month="*", day="*", hour=h, minute=m, second="0" + ) + if configs[i]["enabled"]: + try : + scheduler.remove_job(i) # on reset le job + except Exception as e: + print(f"\033[33merror with deleting config {i} : {e}\033[0m") + + try : + scheduler.add_job( # on relance le job + start_ms, # --- + trigger=TriggerDict[i], # --- + args=[i], # --- + name="Daily start", # --- + id=i # --- + ) + print("\033[36m" + f"successfully created config {i}" + "\033[0m") + except Exception as e: + print(f"\033[33merror with creating config {i} : {e}\033[0m") + else : + try : + scheduler.remove_job(i) + except Exception as e : + print(f"\033[33merror with deleting config {i} : {e}\033[0m") + @@ -245,7 +272,7 @@ def override_get(): @app.route("/override/", methods=["post"]) -def override(): +def override_post(): with open("./user_data/configs.json", "r") as inFile: configs = json.load(inFile) @@ -262,7 +289,7 @@ def override(): with open("./user_data/configs.json", "w") as inFile: json.dump(configs, inFile) - + update_jobs() return(render_template("override.html", data=configs)) @@ -338,7 +365,6 @@ def config_post(): return(render_template("config.html", data=configs, discords=discords, proxys=proxys, configs=configs, len=maxi(configs))) - def maxi(dict): m = 0 for i in dict : diff --git a/Flask/templates/override.html b/Flask/templates/override.html index 8105ee9..948d045 100644 --- a/Flask/templates/override.html +++ b/Flask/templates/override.html @@ -47,10 +47,10 @@ {{data[i]['name']}} - + - +