mirror of
https://github.com/michivonah/themepark-alerts.git
synced 2025-12-23 04:36:37 +01:00
Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f3d3fced24 | |||
| 8ac30fd663 | |||
| 566b7e8de1 | |||
| 85d05e0e66 | |||
| 0988256239 | |||
| 5e07460615 | |||
| 921442289a | |||
| 06ba3ef0e1 |
4 changed files with 78 additions and 45 deletions
18
.github/workflows/dockerhub-autopublishing.yml
vendored
18
.github/workflows/dockerhub-autopublishing.yml
vendored
|
|
@ -1,18 +0,0 @@
|
||||||
name: Docker-Hub-Autopublishing
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: debian-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Build docker image and push to docker hub
|
|
||||||
run: |
|
|
||||||
echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u michivonah --password-stdin
|
|
||||||
docker image build -t michivonah/ep-alerts:latest .
|
|
||||||
docker push michivonah/ep-alerts:latest
|
|
||||||
25
.github/workflows/image-build.yml
vendored
Normal file
25
.github/workflows/image-build.yml
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
name: Build Docker Image
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: push docker image to docker hub
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: login to docker hub
|
||||||
|
id: docker-hub
|
||||||
|
env:
|
||||||
|
username: ${{secrets.DOCKER_USERNAME}}
|
||||||
|
password: ${{secrets.DOCKER_TOKEN}}
|
||||||
|
run: |
|
||||||
|
docker login -u $username -p $password
|
||||||
|
- name: build the docker image
|
||||||
|
id: build-docker-image
|
||||||
|
run: |
|
||||||
|
docker build -t michivonah/ep-alerts:latest .
|
||||||
|
- name: push the docker image
|
||||||
|
id: push-docker-image
|
||||||
|
run: docker push michivonah/ep-alerts:latest
|
||||||
27
main.py
27
main.py
|
|
@ -26,19 +26,30 @@ def sendMessage(message, notificationType):
|
||||||
header = {
|
header = {
|
||||||
"Authorization":f"Bearer {accessToken}"
|
"Authorization":f"Bearer {accessToken}"
|
||||||
}
|
}
|
||||||
|
try:
|
||||||
response = requests.post(url=endpoint, headers=header, data=message)
|
response = requests.post(url=endpoint, headers=header, data=message)
|
||||||
else: response = requests.post(url=endpoint, data=message)
|
except Exception as error:
|
||||||
|
raise Exception(f"Got an error while sending the notification: {error}")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
response = requests.post(url=endpoint, data=message)
|
||||||
|
except Exception as error:
|
||||||
|
raise Exception(f"Got an error while sending the notification: {error}")
|
||||||
return response
|
return response
|
||||||
case "discord" | _:
|
case "discord" | _:
|
||||||
endpoint = os.getenv('DISCORD_WEBHOOK')
|
endpoint = os.getenv('DISCORD_WEBHOOK')
|
||||||
data = {
|
data = {
|
||||||
"content": message,
|
"content": message,
|
||||||
}
|
}
|
||||||
|
try:
|
||||||
response = requests.post(url=endpoint, json=data)
|
response = requests.post(url=endpoint, json=data)
|
||||||
return response
|
return response
|
||||||
|
except Exception as error:
|
||||||
|
raise Exception(f"Got an error while sending the notification: {error}")
|
||||||
|
|
||||||
# Check for the current waiting times
|
# Check for the current waiting times
|
||||||
def checkTimes(subscribedAttractions, themepark):
|
def checkTimes(subscribedAttractions, themepark):
|
||||||
|
try:
|
||||||
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
endpoint = "https://api.wartezeiten.app/v1/waitingtimes"
|
||||||
|
|
||||||
header = {
|
header = {
|
||||||
|
|
@ -47,9 +58,16 @@ def checkTimes(subscribedAttractions, themepark):
|
||||||
}
|
}
|
||||||
|
|
||||||
req = requests.get(url=endpoint, headers=header)
|
req = requests.get(url=endpoint, headers=header)
|
||||||
|
except:
|
||||||
|
raise Exception(f"API Request to endpoint {endpoint} failed.")
|
||||||
|
try:
|
||||||
result = req.json()
|
result = req.json()
|
||||||
|
except:
|
||||||
|
raise Exception("Format of API response is invalid. (JSON expected)")
|
||||||
|
try:
|
||||||
attractions = result
|
attractions = result
|
||||||
for attraction in attractions:
|
for attraction in attractions:
|
||||||
|
if isinstance(attraction, dict) and "code" in attraction:
|
||||||
if attraction["code"] in subscribedAttractions:
|
if attraction["code"] in subscribedAttractions:
|
||||||
if attraction["status"] == "opened":
|
if attraction["status"] == "opened":
|
||||||
refreshTime = 30
|
refreshTime = 30
|
||||||
|
|
@ -61,6 +79,10 @@ def checkTimes(subscribedAttractions, themepark):
|
||||||
currentTimes[attraction["code"]] = attraction["waitingtime"]
|
currentTimes[attraction["code"]] = attraction["waitingtime"]
|
||||||
else:
|
else:
|
||||||
refreshTime = 180
|
refreshTime = 180
|
||||||
|
else:
|
||||||
|
print(f"Info: Attraction was skipped because it has an invalid data structure. Affected attraction: {attraction}")
|
||||||
|
except Exception as error:
|
||||||
|
raise Exception(f"Got an error while checking for differences since the last API call. Error: {error}")
|
||||||
|
|
||||||
# Main Loop
|
# Main Loop
|
||||||
# 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
|
||||||
|
|
@ -70,7 +92,10 @@ if __name__ == '__main__':
|
||||||
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:
|
||||||
|
try:
|
||||||
checkTimes(subscribedAttractions, themepark)
|
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())}")
|
||||||
|
except Exception as error:
|
||||||
|
raise Exception(error)
|
||||||
time.sleep(refreshTime)
|
time.sleep(refreshTime)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
# requirements.txt
|
# requirements.txt
|
||||||
python-dotenv==1.0.1
|
python-dotenv==1.1.1
|
||||||
pipenv==2024.1.0
|
pipenv==2025.0.4
|
||||||
|
requests==2.32.5
|
||||||
Loading…
Add table
Add a link
Reference in a new issue