use scheduler and avoid abusing ntfy.sh
This commit is contained in:
parent
84f8e4b299
commit
c490af0732
14
checker.py
14
checker.py
@ -4,7 +4,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
#import schedule
|
import schedule
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
previous = defaultdict(int)
|
previous = defaultdict(int)
|
||||||
@ -38,6 +38,7 @@ def check(item):
|
|||||||
|
|
||||||
|
|
||||||
def notify(data, url=NTFY_CHANNEL):
|
def notify(data, url=NTFY_CHANNEL):
|
||||||
|
print(f"Sending {data} to {url}")
|
||||||
requests.post(url,
|
requests.post(url,
|
||||||
data=data.encode(encoding='utf-8'))
|
data=data.encode(encoding='utf-8'))
|
||||||
|
|
||||||
@ -48,12 +49,17 @@ def check_watchlist():
|
|||||||
item = client.get_item(id)
|
item = client.get_item(id)
|
||||||
total += check(item)
|
total += check(item)
|
||||||
time.sleep(random.randint(2, 10))
|
time.sleep(random.randint(2, 10))
|
||||||
|
|
||||||
|
def notify_all():
|
||||||
|
total = sum(previous.values())
|
||||||
notify(f"List checked. Total available: {total}", url=NTFY_CHANNEL_DEBUG)
|
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:
|
while True:
|
||||||
#schedule.run_pending()
|
schedule.run_pending()
|
||||||
check_watchlist()
|
#check_watchlist()
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
Loading…
Reference in New Issue
Block a user