From 6f4d624fb104c1cb00c79e57dc1a9e7dac83a066 Mon Sep 17 00:00:00 2001 From: garland Date: Sun, 18 Aug 2024 11:25:41 -0700 Subject: [PATCH] nexus5 --- .../nexus-trusted-traveler-scheduler-1.yml | 4 +-- .../src/notifcation_handler.py | 27 +++++++------------ .../src/schedule_retriever.py | 7 ++--- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.github/workflows/nexus-trusted-traveler-scheduler-1.yml b/.github/workflows/nexus-trusted-traveler-scheduler-1.yml index 8f21ef25..fec77545 100644 --- a/.github/workflows/nexus-trusted-traveler-scheduler-1.yml +++ b/.github/workflows/nexus-trusted-traveler-scheduler-1.yml @@ -25,10 +25,10 @@ on: ## * * * * * schedule: ## Testing run every 5 minutes - # - cron: '*/5 * * * *' + - cron: '*/5 * * * *' ## Run every 5 hours on minute 37 - - cron: '37 */5 * * *' + # - cron: '37 */5 * * *' env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN_NEXUS }} # Sends to the nexus channel. In the format of: slack://xxx/xxx/xxx diff --git a/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/notifcation_handler.py b/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/notifcation_handler.py index 50d3f016..c7f30f81 100644 --- a/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/notifcation_handler.py +++ b/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/notifcation_handler.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING, List import apprise -import re from .schedule import Schedule from .notification_level import NotificationLevel @@ -53,23 +52,15 @@ def send_notification(self, body: str, level: int = 1) -> None: title = "Trusted Traveler Scheduler" - pattern = r"Sun|Fri|Sat" - match = re.search(pattern, body) - print("GarDebug: in sending notification") - - if match: - print(f"GarDebug: Sending notification: {body}") - apobj = apprise.Apprise(self.notification_urls) - result = apobj.notify(title=title, body=body, body_format=apprise.NotifyFormat.TEXT) - - # If you encounter Apprise errors, https://github.com/caronc/apprise/wiki/Development_LogCapture - # may be useful. - if result is None: - print('{datetime.today():%Y/%m/%d %H:%M:%S}: error: No notifications sent (configuration error)') - elif result is False: - print('{datetime.today():%Y/%m/%d %H:%M:%S}: error: At least 1 notification failed to send') - else: - print(f"GarDebug: Skipping notification: {body}") + apobj = apprise.Apprise(self.notification_urls) + result = apobj.notify(title=title, body=body, body_format=apprise.NotifyFormat.TEXT) + + # If you encounter Apprise errors, https://github.com/caronc/apprise/wiki/Development_LogCapture + # may be useful. + if result is None: + print('{datetime.today():%Y/%m/%d %H:%M:%S}: error: No notifications sent (configuration error)') + elif result is False: + print('{datetime.today():%Y/%m/%d %H:%M:%S}: error: At least 1 notification failed to send') def new_appointment(self, location_id: int, appointments: List[Schedule]) -> None: """ diff --git a/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/schedule_retriever.py b/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/schedule_retriever.py index ba2e7ae1..e26e601a 100644 --- a/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/schedule_retriever.py +++ b/nexus-global-entry/trusted-traveler-scheduler/trusted-traveler-scheduler/src/schedule_retriever.py @@ -147,11 +147,11 @@ def _get_schedule(self, location_id: int) -> None: """ try: time.sleep(1) - print("getting appointments") + print("getting schedule") appointments = requests.get( GOES_URL_FORMAT.format(location_id), timeout=30 ).json() - print("got appointments") + print("got schedule") if not appointments: print(f"{datetime.today():%Y/%m/%d %H:%M:%S}: No active appointments available for location {location_id}.") @@ -164,9 +164,6 @@ def _get_schedule(self, location_id: int) -> None: schedule = self._evaluate_timestamp( schedule, location_id, appointment["startTimestamp"] ) - - print(f"GarDebug: appointment-startTimestamp: {appointment["startTimestamp"]}") - all_active_appointments.append(datetime.strptime(appointment["startTimestamp"], "%Y-%m-%dT%H:%M").isoformat()) self._clear_database_of_claimed_appointments(location_id, all_active_appointments)