use scheduler and avoid abusing ntfy.sh
This commit is contained in:
parent
84f8e4b299
commit
c490af0732
18
checker.py
18
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)
|
||||
|
Loading…
Reference in New Issue
Block a user