added ntfy as alternative notfication service, support for other themeparks & more customization

This commit is contained in:
Michi 2024-10-12 12:34:36 +02:00
parent ff4f5e10ae
commit 6cbdb6a61e
5 changed files with 52 additions and 30 deletions

49
main.py
View file

@ -1,11 +1,10 @@
# Europapark Waiting Time alerts to Discord
# Michi von Ah - October 2023
# Themepark Wait Time Alerts
# Michi von Ah - October 2023 (Last Updated on October 2024)
# Thanks to https://www.wartezeiten.app/ for their API
import requests
import os
from dotenv import load_dotenv
from discord_webhook import DiscordWebhook
import time
load_dotenv()
@ -13,25 +12,41 @@ load_dotenv()
# Global defintions
subscribedAttractions = os.getenv('SUBS').split(",")
currentTimes = {}
refreshTime = 30
refreshTime = int(os.getenv('CHECK_INTERVAL')) if os.getenv('CHECK_INTERVAL') else 30
notificationType = os.getenv('NOTIFICATION_TYPE') if os.getenv('NOTIFICATION_TYPE') else "discord"
themepark = os.getenv('THEMEPARK') if os.getenv('THEMEPARK') else "europapark"
# Send messagess via Discord Webhook
def sendMessage(message):
webhookUrl = os.getenv('DISCORD_WEBHOOK')
webhook = DiscordWebhook(url=webhookUrl, content=message)
response = webhook.execute()
return response
# Send messagess via specified notificationType
def sendMessage(message, notificationType):
match notificationType.lower():
case "ntfy":
endpoint = os.getenv('NTFY_URL')
accessToken = os.getenv('NTFY_ACCESS_TOKEN')
if accessToken:
header = {
"Authorization":f"Bearer {accessToken}"
}
response = requests.post(url=endpoint, headers=header, data=message)
else: response = requests.post(url=endpoint, data=message)
return response
case "discord" | _:
endpoint = os.getenv('DISCORD_WEBHOOK')
data = {
"content": message,
}
response = requests.post(url=endpoint, json=data)
return response
# Check for the current waiting times
def checkTimes(subscribedAttractions):
def checkTimes(subscribedAttractions, themepark):
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
header = {
"language":"de",
"park":"europapark"
"park":themepark
}
req = requests.get(url = endpoint, headers = header)
req = requests.get(url=endpoint, headers=header)
result = req.json()
attractions = result
for attraction in attractions:
@ -40,9 +55,9 @@ def checkTimes(subscribedAttractions):
refreshTime = 30
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!")
sendMessage(f"Waiting time of {attraction['name']} sank to {attraction['waitingtime']} Minutes!", notificationType)
elif currentTimes[attraction["code"]] < attraction["waitingtime"]:
sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!")
sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!", notificationType)
currentTimes[attraction["code"]] = attraction["waitingtime"]
else:
refreshTime = 180
@ -51,11 +66,11 @@ def checkTimes(subscribedAttractions):
# Checks every 30 seconds for changes in the waiting times of the subscribed attractions
# If some attractions are closed the check will only be executed every 180 seconds
if __name__ == '__main__':
print("EP Waiting Time Alerting Tool")
print("Themepark Wait Time Alerts")
print("By Michi von Ah")
print("Big thanks to the wartezeiten.app API!")
while True:
checkTimes(subscribedAttractions)
checkTimes(subscribedAttractions, themepark)
print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}")
time.sleep(refreshTime)