mirror of
https://github.com/michivonah/themepark-alerts.git
synced 2025-12-22 20:36:27 +01:00
create script for alerting to discord
This commit is contained in:
parent
51dccb0898
commit
9f8df3931b
1 changed files with 25 additions and 10 deletions
35
main.py
35
main.py
|
|
@ -5,18 +5,33 @@ from discord_webhook import DiscordWebhook
|
|||
|
||||
load_dotenv()
|
||||
|
||||
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
||||
# Global defintions
|
||||
subscribedAttractions = ["383533", "383530", "323530", "323030", "353030", "393030"]
|
||||
waitingtimeAlert = 30
|
||||
|
||||
header = {
|
||||
"language":"de",
|
||||
"park":"europapark"
|
||||
}
|
||||
# Functions
|
||||
def sendMessage(message):
|
||||
webhookUrl = os.getenv('DISCORD_WEBHOOK')
|
||||
webhook = DiscordWebhook(url=webhookUrl, content=message)
|
||||
response = webhook.execute()
|
||||
|
||||
req = requests.get(url = endpoint, params = header)
|
||||
def checkTimes(subscribedAttractions, alertlimit):
|
||||
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
||||
|
||||
result = req.json()
|
||||
header = {
|
||||
"language":"de",
|
||||
"park":"europapark"
|
||||
}
|
||||
|
||||
webhookUrl = os.getenv('DISCORD_WEBHOOK')
|
||||
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!")
|
||||
|
||||
# Main
|
||||
if __name__ == '__main__':
|
||||
checkTimes(subscribedAttractions, waitingtimeAlert)
|
||||
|
||||
webhook = DiscordWebhook(url=webhookUrl, content=result["error"])
|
||||
response = webhook.execute()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue