Skip to content

Commit

Permalink
nexus5
Browse files Browse the repository at this point in the history
  • Loading branch information
garland committed Aug 17, 2024
1 parent 23e7ef9 commit 505d90b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 37 deletions.
69 changes: 69 additions & 0 deletions nexus-global-entry/trusted-traveler-scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,72 @@ python3 ttp.py -t
```
python3 ttp.py -u slack://xxx/xxx/xxx
```


"location_ids": [ 5020, 5026, 5021, 5022, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5060, 5080, 5100, 5101, 5120, 5160, 5161, 5223, 5500, 5520, 16502, 16511, 16546 ],



def _get_schedule(self, location_id: int) -> None:
"""
Retrieves the schedule for the given location ID and evaluates the available appointment times. If there are
any new appointments that meet the criteria specified in the configuration, a notification is sent.

:param location_id: The ID of the location to retrieve the schedule for.
:type location_id: int
:return: None
"""
try:
time.sleep(1)
appointments = requests.get(
GOES_URL_FORMAT.format(location_id), timeout=30
).json()

if not appointments:
print(f"{datetime.today():%Y/%m/%d %H:%M:%S}: No active appointments available for location {location_id}.")
return

hasWeekendSchedule = False
schedule = []
all_active_appointments = []
for appointment in appointments:
if appointment["active"]:
schedule = self._evaluate_timestamp(
schedule, location_id, appointment["startTimestamp"]
)

datetime_obj = datetime.strptime(appointment["startTimestamp"], "%Y-%m-%dT%H:%M")
formatted_string = datetime_obj.strftime("%A, %B %d, %H:%M")
print(f"GarDebug: the appointment datetime stamp formatted_string: {formatted_string} | {location_id}")

pattern = r"Sunday|Friday|Saturday"
match = re.search(pattern, formatted_string)

if match:
print("The string contains a weekend day.")
hasWeekendSchedule = True
else:
print("The string does not contain a weekend day.")
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)

print("here")

if not schedule:
return

print("here2")

# if hasWeekendSchedule:
print("GarDebug: notify")
self.notification_handler.new_appointment(location_id, schedule)

except OSError:
return


Nexus onlY; 5020, 5120, 5160, 16511
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"current_appointment_date": "December 31, 2024",
"location_ids": [ 5020, 5026 ],
"location_ids": [5020, 5026, 5021, 5022, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5060, 5080, 5100, 5101, 5120, 5160, 5161, 5223, 5500, 5520, 16502, 16511, 16546 ],
"notification_level": 1,
"notification_urls": [ ],
"notification_urls": [ "slack://T033DF408/B07GLNAJE86/uvAnvJ4IDzKkQikngVElxDOh" ],
"retrieval_interval": "1m",
"start_appointment_time": "00:00",
"end_appointment_time": "23:59"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING, List

import apprise
import re
from .schedule import Schedule

from .notification_level import NotificationLevel
Expand Down Expand Up @@ -52,15 +53,23 @@ def send_notification(self, body: str, level: int = 1) -> None:

title = "Trusted Traveler Scheduler"

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')
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}")

def new_appointment(self, location_id: int, appointments: List[Schedule]) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def _get_schedule(self, location_id: int) -> None:
"""
try:
time.sleep(1)
print("getting appointments")
appointments = requests.get(
GOES_URL_FORMAT.format(location_id), timeout=30
).json()
print("got appointments")

if not appointments:
print(f"{datetime.today():%Y/%m/%d %H:%M:%S}: No active appointments available for location {location_id}.")
return

hasWeekendSchedule = False

schedule = []
all_active_appointments = []
Expand All @@ -165,28 +165,7 @@ def _get_schedule(self, location_id: int) -> None:
schedule, location_id, appointment["startTimestamp"]
)

## GarDebug
foo = datetime.strptime(appointment["startTimestamp"], "%Y-%m-%dT%H:%M").isoformat()
print(f"GarDebug: the appointment datetime stamp foo: {foo}")

datetime_obj = datetime.strptime(appointment["startTimestamp"], "%Y-%m-%dT%H:%M")
formatted_string = datetime_obj.strftime("%A, %B %d, %H:%M")
print(f"GarDebug: the appointment datetime stamp formatted_string: {formatted_string}")


# date_string1 = datetime.strftime(appointment["startTimestamp"], '%a, %B %d, %Y')
# print(f"GarDebug: the appointment datetime stamp date_string1: {date_string1}")
# date_string2 = datetime.strftime(appointment.appointment_date, '%a, %B %d, %Y')
# print(f"GarDebug: the appointment datetime stamp date_string2: {date_string2}")
# sys.exit()

weekdays = ["Sunday", "Friday", "Saturday"]
if any(weekday in formatted_string.split() for weekday in weekdays):
print("The string contains a weekend day.")
hasWeekendSchedule = True
else:
print("The string does not contain a weekend day.")

print(f"GarDebug: appointment-startTimestamp: {appointment["startTimestamp"]}")

all_active_appointments.append(datetime.strptime(appointment["startTimestamp"], "%Y-%m-%dT%H:%M").isoformat())

Expand All @@ -195,8 +174,7 @@ def _get_schedule(self, location_id: int) -> None:
if not schedule:
return

if hasWeekendSchedule:
self.notification_handler.new_appointment(location_id, schedule)
self.notification_handler.new_appointment(location_id, schedule)


except OSError:
Expand Down

0 comments on commit 505d90b

Please sign in to comment.