create script for alerting to discord

This commit is contained in:
michivonah 2023-10-02 21:49:12 +02:00
parent 51dccb0898
commit 9f8df3931b

25
main.py
View file

@ -5,6 +5,17 @@ from discord_webhook import DiscordWebhook
load_dotenv()
# Global defintions
subscribedAttractions = ["383533", "383530", "323530", "323030", "353030", "393030"]
waitingtimeAlert = 30
# Functions
def sendMessage(message):
webhookUrl = os.getenv('DISCORD_WEBHOOK')
webhook = DiscordWebhook(url=webhookUrl, content=message)
response = webhook.execute()
def checkTimes(subscribedAttractions, alertlimit):
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
header = {
@ -12,11 +23,15 @@ header = {
"park":"europapark"
}
req = requests.get(url = endpoint, params = header)
req = requests.get(url = endpoint, headers = header)
result = req.json()
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!")
webhookUrl = os.getenv('DISCORD_WEBHOOK')
# Main
if __name__ == '__main__':
checkTimes(subscribedAttractions, waitingtimeAlert)
webhook = DiscordWebhook(url=webhookUrl, content=result["error"])
response = webhook.execute()