From 30ec4322eb0415cef3eb4ec81606c7b595bd5926 Mon Sep 17 00:00:00 2001 From: TheBidouilleur Date: Tue, 27 Oct 2020 11:13:33 +0100 Subject: [PATCH] Ajout de Gotify pour les notifications --- run.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/run.py b/run.py index ade2fae..78f7480 100644 --- a/run.py +++ b/run.py @@ -1,10 +1,11 @@ from datetime import datetime -import psutil -import time +import psutil, time, requests + from win10toast import ToastNotifier toaster = ToastNotifier() from datetime import datetime +from config import Gotify datetime.today().strftime('%Y-%m-%d') @@ -47,7 +48,7 @@ def countdown(founded_process): secondes = '0' + str(secondes) - + send_gotify('NSL ' + searching_process, "Uptime du processus : %s:%s:%s " % (heures, minutes, secondes) ) print("Uptime du processus : %s:%s:%s " % (heures, minutes, secondes)) toaster.show_toast("NoSocialLife Counter","Arret du programme : " + searching_process ) toaster.show_toast("NoSocialLife Counter","Uptime du processus : %s:%s:%s " % (heures, minutes, secondes)) @@ -57,6 +58,7 @@ def countdown(founded_process): f.write(date + " | Programme : " + searching_process + " | Uptime du processus : %s:%s:%s " % (heures, minutes, secondes)) f.close() + def main(): toaster.show_toast("NoSocialLife Counter","Programme recherché : " + searching_process ) process_running = False @@ -77,7 +79,12 @@ def main(): countdown(founded_process) - +def send_gotify(title, message): + resp = requests.post(Gotify['URL'] + '?token=' + Gotify['token_gotify'] , json={ + "message": message, + "priority": 2, + "title": title + }) def catch_process(searching_process): catched = False @@ -92,8 +99,5 @@ def catch_process(searching_process): if __name__ == '__main__': - try : - main() - except : - print("Erreur, Redemarrage du script") - main() + + main()