mirror of
https://github.com/michivonah/themepark-alerts.git
synced 2025-12-22 20:36:27 +01:00
added ntfy as alternative notfication service, support for other themeparks & more customization
This commit is contained in:
parent
ff4f5e10ae
commit
6cbdb6a61e
5 changed files with 52 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
.env
|
.env
|
||||||
__pycache__
|
__pycache__
|
||||||
|
venv
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM python:3.11
|
FROM python:3.12
|
||||||
|
|
||||||
# Create directory
|
# Create directory
|
||||||
RUN mkdir app
|
RUN mkdir app
|
||||||
|
|
@ -11,6 +11,7 @@ COPY requirements.txt .
|
||||||
# Set enviromental variables
|
# Set enviromental variables
|
||||||
ENV DISCORD_WEBHOOK "https://discord.com/api/webhooks/XXXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYY"
|
ENV DISCORD_WEBHOOK "https://discord.com/api/webhooks/XXXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYY"
|
||||||
ENV SUBS "383533, 323530, 353030"
|
ENV SUBS "383533, 323530, 353030"
|
||||||
|
ENV NOTIFICATION_TYPE "discord"
|
||||||
|
|
||||||
# Install needed packages
|
# Install needed packages
|
||||||
RUN pip3 install --upgrade pip
|
RUN pip3 install --upgrade pip
|
||||||
|
|
|
||||||
22
README.md
22
README.md
|
|
@ -1,10 +1,10 @@
|
||||||
# Europapark Waitingtime Alerts via Discord Webhook
|
# Themepark Wait Time Alerts
|
||||||
A tool which alerts you when the waiting times of subscribed europapark attractions sinks or increase. Powered by the [wartezeiten.app](https://www.wartezeiten.app/page/api.html) API.
|
A tool which alerts you when the waiting times of subscribed attractions in your favourite themepark sinks or increase. The notifications are sent to a Discord webhook or to your ntfy-server. Powered by the [wartezeiten.app](https://www.wartezeiten.app/page/api.html) API.
|
||||||
|
|
||||||
GitHub: https://github.com/michivonah/europapark-alerts <br>
|
GitHub: https://github.com/michivonah/europapark-alerts <br>
|
||||||
Docker: https://hub.docker.com/r/michivonah/ep-alerts
|
Docker: https://hub.docker.com/r/michivonah/ep-alerts
|
||||||
|
|
||||||
Host it on your server:
|
Host it on your own server:
|
||||||
1. Install docker on your system
|
1. Install docker on your system
|
||||||
|
|
||||||
```apt-get install docker.io docker-compose -y```
|
```apt-get install docker.io docker-compose -y```
|
||||||
|
|
@ -15,9 +15,15 @@ Host it on your server:
|
||||||
## Enviormental variables
|
## Enviormental variables
|
||||||
These environment variables are supported
|
These environment variables are supported
|
||||||
|
|
||||||
| Variable | Description | Example |
|
| Variable | Description | Example | Required |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| DISCORD_WEBHOOK | The URL of your discord webhook | ``https://discord.com/api/webhooks/XXXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYY`` |
|
| NOTIFICATION_TYPE | Define which type of notification you want use. Supported are: discord, ntfy | ``discord`` | yes |
|
||||||
| SUBS | Your subscribed attractions with ID from wartezeiten.app API | ``383533,323530,353030`` |
|
| CHECK_INTERVAL | Defines how often the API is requested and the waittimes are checked for updates (in seconds) | ``30`` | no |
|
||||||
|
| DISCORD_WEBHOOK | The URL of your discord webhook | ``https://discord.com/api/webhooks/XXXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYY`` | no* |
|
||||||
|
| NTFY_URL | The URL to your ntfy topic | ``https://ntfy.example.com/mytopic`` | no* |
|
||||||
|
| NTFY_ACCESS_TOKEN | Optional access token for authenticating against your ntfy server if authentication is enabled. | ``tk_2cdbcfea1702cc3bd2c874beab1`` | no |
|
||||||
|
| SUBS | Your subscribed attractions with ID from wartezeiten.app API | ``383533,323530,353030`` | yes |
|
||||||
|
| THEMEPARK | Select your desired themepark from the wartezeiten.app API. Defaults to ``europapark`` | ``europapark`` | no |
|
||||||
|
|
||||||
> Required enviromental variables: DISCORD_WEBHOOK, SUBS
|
|
||||||
|
> *Depending on the selected service for notifications (``NOTIFICATION_TYPE``) ether ``DISCORD_WEBHOOK`` or ``NTFY_URL`` is required.
|
||||||
45
main.py
45
main.py
|
|
@ -1,11 +1,10 @@
|
||||||
# Europapark Waiting Time alerts to Discord
|
# Themepark Wait Time Alerts
|
||||||
# Michi von Ah - October 2023
|
# Michi von Ah - October 2023 (Last Updated on October 2024)
|
||||||
# Thanks to https://www.wartezeiten.app/ for their API
|
# Thanks to https://www.wartezeiten.app/ for their API
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from discord_webhook import DiscordWebhook
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
@ -13,22 +12,38 @@ load_dotenv()
|
||||||
# Global defintions
|
# Global defintions
|
||||||
subscribedAttractions = os.getenv('SUBS').split(",")
|
subscribedAttractions = os.getenv('SUBS').split(",")
|
||||||
currentTimes = {}
|
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
|
# Send messagess via specified notificationType
|
||||||
def sendMessage(message):
|
def sendMessage(message, notificationType):
|
||||||
webhookUrl = os.getenv('DISCORD_WEBHOOK')
|
match notificationType.lower():
|
||||||
webhook = DiscordWebhook(url=webhookUrl, content=message)
|
case "ntfy":
|
||||||
response = webhook.execute()
|
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
|
return response
|
||||||
|
|
||||||
# Check for the current waiting times
|
# Check for the current waiting times
|
||||||
def checkTimes(subscribedAttractions):
|
def checkTimes(subscribedAttractions, themepark):
|
||||||
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
||||||
|
|
||||||
header = {
|
header = {
|
||||||
"language":"de",
|
"language":"de",
|
||||||
"park":"europapark"
|
"park":themepark
|
||||||
}
|
}
|
||||||
|
|
||||||
req = requests.get(url=endpoint, headers=header)
|
req = requests.get(url=endpoint, headers=header)
|
||||||
|
|
@ -40,9 +55,9 @@ def checkTimes(subscribedAttractions):
|
||||||
refreshTime = 30
|
refreshTime = 30
|
||||||
if not attraction["code"] in currentTimes: currentTimes[attraction["code"]] = attraction["waitingtime"];
|
if not attraction["code"] in currentTimes: currentTimes[attraction["code"]] = attraction["waitingtime"];
|
||||||
if 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"]:
|
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"]
|
currentTimes[attraction["code"]] = attraction["waitingtime"]
|
||||||
else:
|
else:
|
||||||
refreshTime = 180
|
refreshTime = 180
|
||||||
|
|
@ -51,11 +66,11 @@ def checkTimes(subscribedAttractions):
|
||||||
# Checks every 30 seconds for changes in the waiting times of the subscribed attractions
|
# 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 some attractions are closed the check will only be executed every 180 seconds
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print("EP Waiting Time Alerting Tool")
|
print("Themepark Wait Time Alerts")
|
||||||
print("By Michi von Ah")
|
print("By Michi von Ah")
|
||||||
print("Big thanks to the wartezeiten.app API!")
|
print("Big thanks to the wartezeiten.app API!")
|
||||||
while True:
|
while True:
|
||||||
checkTimes(subscribedAttractions)
|
checkTimes(subscribedAttractions, themepark)
|
||||||
print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}")
|
print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}")
|
||||||
time.sleep(refreshTime)
|
time.sleep(refreshTime)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# requirements.txt
|
# requirements.txt
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.1
|
||||||
#discord.py
|
pipenv==2024.1.0
|
||||||
discord-webhook==1.3.0
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue