Skip to content

Instantly share code, notes, and snippets.

@joshuajnoble
Last active August 26, 2024 17:28
Show Gist options
  • Save joshuajnoble/7e4fca61069dc24ae6d389a40d083391 to your computer and use it in GitHub Desktop.
Save joshuajnoble/7e4fca61069dc24ae6d389a40d083391 to your computer and use it in GitHub Desktop.
import time
from twilio.rest import Client
import requests
from dateutil import parser
# Create client
account_sid = 'xxx' # Grab from Twilio
auth_token = 'xxx' # Grab from Twilio
client = Client(account_sid, auth_token)
def notify(message):
print(message)
message = client.messages.create(
body=message,
from_='+1xxxxxxxxx', # Grab from Twilio (e.g. +12061231231)
to='+1xxxxxxxxx' # Insert your own phone number (e.g. +12067897897)
)
# The last appointment that we've notified about, to prevent duplicate notifications
prev_start = None
def check():
global prev_start
# Check if any appointments are available, and if so, notify
# use Blaine
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 in the future, look backwards
start = appt.get('startTimestamp', '2099-01-01T00:00')
# Prevent duplicates
if start != prev_start:
print(f'Found appt on {start}')
prev_start = start
date = parser.parse(start)
if date.year == 2024:
notify(f'Found appointment on {start}')
return False
while True:
if check():
# Wait for 15 mins after error
time.sleep(60*15)
else:
# Wait 1 min otherwise, better to keep this fast b/c all the other scraping services do too
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment