mirror of
https://github.com/michivonah/themepark-alerts.git
synced 2025-12-22 20:36:27 +01:00
optimize script for understanding
This commit is contained in:
parent
4c47182500
commit
cd1623af8a
1 changed files with 11 additions and 2 deletions
13
main.py
13
main.py
|
|
@ -1,3 +1,7 @@
|
||||||
|
# Europapark Waiting Time alerts to Discord
|
||||||
|
# Michi von Ah - October 2023
|
||||||
|
# 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
|
||||||
|
|
@ -10,12 +14,13 @@ load_dotenv()
|
||||||
subscribedAttractions = ["383533", "383530", "323530", "323030", "353030", "393030"]
|
subscribedAttractions = ["383533", "383530", "323530", "323030", "353030", "393030"]
|
||||||
currentTimes = {}
|
currentTimes = {}
|
||||||
|
|
||||||
# Functions
|
# Send messagess via Discord Webhook
|
||||||
def sendMessage(message):
|
def sendMessage(message):
|
||||||
webhookUrl = os.getenv('DISCORD_WEBHOOK')
|
webhookUrl = os.getenv('DISCORD_WEBHOOK')
|
||||||
webhook = DiscordWebhook(url=webhookUrl, content=message)
|
webhook = DiscordWebhook(url=webhookUrl, content=message)
|
||||||
response = webhook.execute()
|
response = webhook.execute()
|
||||||
|
|
||||||
|
# Check for the current waiting times
|
||||||
def checkTimes(subscribedAttractions):
|
def checkTimes(subscribedAttractions):
|
||||||
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
||||||
|
|
||||||
|
|
@ -37,8 +42,12 @@ def checkTimes(subscribedAttractions):
|
||||||
sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!")
|
sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!")
|
||||||
currentTimes[attraction["code"]] = attraction["waitingtime"]
|
currentTimes[attraction["code"]] = attraction["waitingtime"]
|
||||||
|
|
||||||
# Main
|
# Main Loop
|
||||||
|
# Checks every 30 seconds for changes in the waiting times of the subscribed attractions
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
print("EP Waiting Time Alerting Tool")
|
||||||
|
print("By Michi von Ah")
|
||||||
|
print("Big thanks to the wartezeiten.app API!")
|
||||||
while True:
|
while True:
|
||||||
checkTimes(subscribedAttractions)
|
checkTimes(subscribedAttractions)
|
||||||
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())}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue