Skip to content

Commit

Permalink
chore(cloud/botb-battles): improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnvgr committed Nov 17, 2024
1 parent 20b40ae commit be297c9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions hosts/cloud/botb_battles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python

# Simple script to notify me about new BotB battles

from request.exceptions import RequestException, HTTPError
from datetime import datetime, timedelta
import requests, time

Expand All @@ -12,9 +15,16 @@ def get_adjusted_time(x):

def ntfy_send(text):
print(f"Sent: \"{text}\"")
resp = requests.post(f"https://ntfy.sh/{NTFY_TOPIC}", data = text.encode(encoding="utf-8"))
if resp.status_code != 200:
print(resp.json())

while True:
try:
requests.post(f"https://ntfy.sh/{NTFY_TOPIC}", data = text.encode(encoding="utf-8"))
break
except HTTPError as e:
print(e.response.json())
except RequestException as e:
print(f"Error: {e}")
time.sleep(600) # 10m

sent_battles = []
sent_battles_ids = set()
Expand All @@ -39,6 +49,6 @@ def ntfy_send(text):

# Collect garbage battles
for battle in sent_battles:
if get_adjusted_time(battle["start"]) > datetime.now():
if datetime.now() > get_adjusted_time(battle["start"]):
sent_battles.remove(battle)
sent_battles_ids.remove(battle["id"])

0 comments on commit be297c9

Please sign in to comment.