From c490af07325db8388facf27693508d6e6f2d1683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 12 Dec 2023 09:13:43 +0100 Subject: [PATCH] use scheduler and avoid abusing ntfy.sh --- checker.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/checker.py b/checker.py index ca5ad40..e6b41bc 100644 --- a/checker.py +++ b/checker.py @@ -4,7 +4,7 @@ import json import time import requests import random -#import schedule +import schedule from collections import defaultdict previous = defaultdict(int) @@ -38,8 +38,9 @@ def check(item): def notify(data, url=NTFY_CHANNEL): - requests.post(url, - data=data.encode(encoding='utf-8')) + print(f"Sending {data} to {url}") + requests.post(url, + data=data.encode(encoding='utf-8')) def check_watchlist(): @@ -48,12 +49,17 @@ def check_watchlist(): item = client.get_item(id) total += check(item) time.sleep(random.randint(2, 10)) + +def notify_all(): + total = sum(previous.values()) notify(f"List checked. Total available: {total}", url=NTFY_CHANNEL_DEBUG) -#schedule.every(1).minutes.do(check_watchlist) +schedule.every(1).minutes.do(check_watchlist) +schedule.every(60).minutes.do(notify_all) + while True: - #schedule.run_pending() - check_watchlist() + schedule.run_pending() + #check_watchlist() time.sleep(30)