Skip to content

Instantly share code, notes, and snippets.

@serg06
Created December 28, 2022 22:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save serg06/ac46defe2d9f568ac39665bd50d2e1b1 to your computer and use it in GitHub Desktop.
Save serg06/ac46defe2d9f568ac39665bd50d2e1b1 to your computer and use it in GitHub Desktop.
Python script for pinging Trusted Traveler Program website for appointments and notifying you by text
import time
from twilio.rest import Client
import requests
from dateutil import parser
# Create client
account_sid = '' # TODO: Grab from Twilio
auth_token = '' # TODO: Grab from Twilio
client = Client(account_sid, auth_token)
def notify(message):
print(message)
message = client.messages.create(
body=message,
from_='', # TODO: Grab from Twilio (e.g. +12061231231)
to='' # TODO: Insert your own phone number (e.g. +12067897897)
)
# The last appointment that we've notified about, to prevent duplicate notifications
prevstart = None
def check():
global prevstart
# Check if any appointments are available, and if so, notify
# Return True on error
# TODO: Update the URL to match your location. (Use network monitor to find the URL in their appointment selector.) This URL points to Seattle's NEXUS center.
resp = requests.get('https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit=1&locationId=5020&minimum=1')
if not resp.ok:
notify(f'Failed with status code {resp.status_code}')
return True
appts = resp.json()
if len(appts) > 0:
appt = appts[0]
start = appt.get('startTimestamp', '2099-01-01T00:00')
# Prevent duplicates
if start != prevstart:
print(f'Found appt on {start}')
prevstart = start
date = parser.parse(start)
if date.year == 2022:
notify(f'Found appointment on {start}')
print(f'Found 0 appts')
return False
while True:
if check():
# Wait for 15 mins after error
time.sleep(60*15)
else:
# Wait 1 min otherwise
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment