From 4c471825004f47811ab6b57492e61805ae843821 Mon Sep 17 00:00:00 2001 From: michivonah Date: Tue, 3 Oct 2023 12:23:55 +0200 Subject: [PATCH] updated script to detected changes instead of fixed limits --- main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index bcc5aa9..e4f8450 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ load_dotenv() # Global defintions subscribedAttractions = ["383533", "383530", "323530", "323030", "353030", "393030"] -waitingtimeAlert = 30 +currentTimes = {} # Functions def sendMessage(message): @@ -16,7 +16,7 @@ def sendMessage(message): webhook = DiscordWebhook(url=webhookUrl, content=message) response = webhook.execute() -def checkTimes(subscribedAttractions, alertlimit): +def checkTimes(subscribedAttractions): endpoint = "https://api.wartezeiten.app/v1/waitingtimes" header = { @@ -29,13 +29,18 @@ def checkTimes(subscribedAttractions, alertlimit): attractions = result for attraction in attractions: if attraction["code"] in subscribedAttractions: - if attraction["waitingtime"] < waitingtimeAlert and attraction["status"] == "opened": - sendMessage(f"Waiting time of {attraction['name']} less than {waitingtimeAlert} Minutes!") + if attraction["status"] == "opened": + if not attraction["code"] in currentTimes: currentTimes[attraction["code"]] = attraction["waitingtime"]; + if currentTimes[attraction["code"]] > attraction["waitingtime"]: + sendMessage(f"Waiting time of {attraction['name']} sank to {attraction['waitingtime']} Minutes!") + elif currentTimes[attraction["code"]] < attraction["waitingtime"]: + sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!") + currentTimes[attraction["code"]] = attraction["waitingtime"] # Main if __name__ == '__main__': while True: - checkTimes(subscribedAttractions, waitingtimeAlert) + checkTimes(subscribedAttractions) print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}") time.sleep(30)