From 06ba3ef0e17ae5006f6d6fc463296fcc543bb9d3 Mon Sep 17 00:00:00 2001 From: michivonah Date: Sat, 12 Oct 2024 13:13:33 +0200 Subject: [PATCH 1/8] create new github action for automated deployment --- .../workflows/dockerhub-autopublishing.yml | 18 ------------- .github/workflows/image-build.yml | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/dockerhub-autopublishing.yml create mode 100644 .github/workflows/image-build.yml diff --git a/.github/workflows/dockerhub-autopublishing.yml b/.github/workflows/dockerhub-autopublishing.yml deleted file mode 100644 index 1444956..0000000 --- a/.github/workflows/dockerhub-autopublishing.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml new file mode 100644 index 0000000..c4f84bc --- /dev/null +++ b/.github/workflows/image-build.yml @@ -0,0 +1,25 @@ +name: Build Docker Image +on: + push: + branches: + - main +jobs: + build: + name: push docker image to docker hub + runs-on: debian-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 \ No newline at end of file From 921442289a0fb38a348d271f97173aedd983e4db Mon Sep 17 00:00:00 2001 From: Michi Date: Sat, 12 Oct 2024 13:16:50 +0200 Subject: [PATCH 2/8] change debian to ubuntu for building the image --- .github/workflows/image-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index c4f84bc..d735988 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -6,7 +6,7 @@ on: jobs: build: name: push docker image to docker hub - runs-on: debian-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: login to docker hub @@ -22,4 +22,4 @@ jobs: docker build -t michivonah/ep-alerts:latest . - name: push the docker image id: push-docker-image - run: docker push michivonah/ep-alerts:latest \ No newline at end of file + run: docker push michivonah/ep-alerts:latest From 5e07460615152b5efc43a4f05a366d6c1809d218 Mon Sep 17 00:00:00 2001 From: michivonah Date: Sat, 12 Oct 2024 13:36:32 +0200 Subject: [PATCH 3/8] fix: add requests as requirement --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fdb4576..762103d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ # requirements.txt python-dotenv==1.0.1 -pipenv==2024.1.0 \ No newline at end of file +pipenv==2024.1.0 +requests==2.32.3 \ No newline at end of file From 09882562399fbebd1bac8966f1d6bd0c89c72da9 Mon Sep 17 00:00:00 2001 From: michivonah Date: Sat, 12 Oct 2024 17:30:47 +0200 Subject: [PATCH 4/8] improved exception & error handling #1 --- main.py | 75 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/main.py b/main.py index e404edd..b2958f1 100644 --- a/main.py +++ b/main.py @@ -26,41 +26,63 @@ def sendMessage(message, notificationType): header = { "Authorization":f"Bearer {accessToken}" } - response = requests.post(url=endpoint, headers=header, data=message) - else: response = requests.post(url=endpoint, data=message) + try: + response = requests.post(url=endpoint, headers=header, 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 case "discord" | _: endpoint = os.getenv('DISCORD_WEBHOOK') data = { "content": message, } - response = requests.post(url=endpoint, json=data) - return response + try: + response = requests.post(url=endpoint, json=data) + return response + except Exception as error: + raise Exception(f"Got an error while sending the notification: {error}") # Check for the current waiting times def checkTimes(subscribedAttractions, themepark): - endpoint = "https://api.wartezeiten.app/v1/waitingtimes" + try: + endpoint = "https://api.wartezeiten.app/v1/waitingtimes" - header = { - "language":"de", - "park":themepark - } + header = { + "language":"de", + "park":themepark + } - req = requests.get(url=endpoint, headers=header) - result = req.json() - attractions = result - for attraction in attractions: - if attraction["code"] in subscribedAttractions: - if attraction["status"] == "opened": - refreshTime = 30 - if not attraction["code"] in currentTimes: currentTimes[attraction["code"]] = attraction["waitingtime"]; - if currentTimes[attraction["code"]] > attraction["waitingtime"]: - sendMessage(f"Waiting time of {attraction['name']} sank to {attraction['waitingtime']} Minutes!", notificationType) - elif currentTimes[attraction["code"]] < attraction["waitingtime"]: - sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!", notificationType) - currentTimes[attraction["code"]] = attraction["waitingtime"] + req = requests.get(url=endpoint, headers=header) + except: + raise Exception(f"API Request to endpoint {endpoint} failed.") + try: + result = req.json() + except: + raise Exception("Format of API response is invalid. (JSON expected)") + try: + attractions = result + for attraction in attractions: + if isinstance(attraction, dict) and "code" in attraction: + if attraction["code"] in subscribedAttractions: + if attraction["status"] == "opened": + refreshTime = 30 + if not attraction["code"] in currentTimes: currentTimes[attraction["code"]] = attraction["waitingtime"]; + if currentTimes[attraction["code"]] > attraction["waitingtime"]: + sendMessage(f"Waiting time of {attraction['name']} sank to {attraction['waitingtime']} Minutes!", notificationType) + elif currentTimes[attraction["code"]] < attraction["waitingtime"]: + sendMessage(f"Waiting time for {attraction['name']} increased to {attraction['waitingtime']} Minutes!", notificationType) + currentTimes[attraction["code"]] = attraction["waitingtime"] + else: + refreshTime = 180 else: - refreshTime = 180 + print(f"Info: Attraction was skipt because it has an invalid data structure. Affacted 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 # 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("Big thanks to the wartezeiten.app API!") while True: - checkTimes(subscribedAttractions, themepark) - print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}") + try: + checkTimes(subscribedAttractions, themepark) + print(f"Checked for updates at {time.strftime('%H:%M:%S', time.localtime())}") + except Exception as error: + raise Exception(error) time.sleep(refreshTime) From 85d05e0e666edadd1b38b324b1246e1440ed6c6e Mon Sep 17 00:00:00 2001 From: michivonah Date: Sun, 13 Oct 2024 12:54:54 +0200 Subject: [PATCH 5/8] fix typo in error message #1 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b2958f1..f31846e 100644 --- a/main.py +++ b/main.py @@ -80,7 +80,7 @@ def checkTimes(subscribedAttractions, themepark): else: refreshTime = 180 else: - print(f"Info: Attraction was skipt because it has an invalid data structure. Affacted attraction: {attraction}") + 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}") From 566b7e8de17681cbe97825a52a2292fbae039518 Mon Sep 17 00:00:00 2001 From: Michi Date: Sun, 7 Sep 2025 20:10:13 +0200 Subject: [PATCH 6/8] add license --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7e26b89 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Michi von Ah + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 8ac30fd663bbc68414df061bb627d290498ddf7c Mon Sep 17 00:00:00 2001 From: michivonah Date: Sat, 27 Sep 2025 18:49:00 +0200 Subject: [PATCH 7/8] update dependencies #1 --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 762103d..a8ecb02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # requirements.txt -python-dotenv==1.0.1 -pipenv==2024.1.0 -requests==2.32.3 \ No newline at end of file +python-dotenv==1.1.1 +pipenv==2025.0.4 +requests==2.32.5 \ No newline at end of file From f3d3fced24e458c29e3a1611142520bff6313b6c Mon Sep 17 00:00:00 2001 From: Michi Date: Sat, 27 Sep 2025 18:49:58 +0200 Subject: [PATCH 8/8] Delete LICENSE.md --- LICENSE.md | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 7e26b89..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 Michi von Ah - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.