Skip to content

Instantly share code, notes, and snippets.

@pradeepbn
Last active September 11, 2022 23:39
Show Gist options
  • Save pradeepbn/9daebb1c4bd08a8298c71c8465a50929 to your computer and use it in GitHub Desktop.
Save pradeepbn/9daebb1c4bd08a8298c71c8465a50929 to your computer and use it in GitHub Desktop.
GE appointment schedule checker
import os
import time
import requests
from datetime import datetime
import subprocess
TTP_TIME_FORMAT = '%Y-%m-%dT%H:%M'
NOTIF_MESSAGE="New slot opened at {start}"
DISPLAY_CMD = '''
on run argv
display notification (item 2 of argv) with title (item 1 of argv)
end run
'''
SOUND_CMD='''
on run
afplay /System/Library/Sounds/Hero.aiff
end run
'''
SOUND_CMD='''
say "New slot is available"
'''
def notify(title, text):
subprocess.call(['osascript', '-e', DISPLAY_CMD, title, text])
subprocess.call(['osascript', '-e', SOUND_CMD])
def getSoonestOpenSlots(cityCode):
url = f"https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit=1&locationId={cityCode}&minimum=1"
payload = {}
headers = {
'Cookie': 'TS01e23915=01ff0b0860fa7e0999329e179d09b83786c63295c7c53fab9a63f2c86a1401190c2dfb03eb6234b6a190c29f53f4c86a24f0685774484b2ffff286e6a22403e48e10417b70'
}
try:
response = requests.request("GET", url, headers=headers, data=payload)
result = response.json()
if len(result) > 0:
appointment=result[0]
if appointment['active']:
timestamp = datetime.strptime(appointment['startTimestamp'], TTP_TIME_FORMAT)
print(timestamp)
return timestamp
except Exception as e:
print("Got an exception: " + str(e))
return None
def main():
while True:
timestamp=getSoonestOpenSlots(5446) #SFO location
# timestamp=getSoonestOpenSlots(8100)
if timestamp:
notify("Slots Available", NOTIF_MESSAGE.format(start=timestamp))
time.sleep(1)
if __name__ == '__main__':
main()
@pradeepbn
Copy link
Author

pradeepbn commented Sep 11, 2022

This script works on macOS.

  • Use python 3
  • The following packages are required:
  • pip3 install requests
  • Run python3 check_ge_appt_schedule.py on a terminal
  • When there is new slot available, it shows the notification on the macOS with a human voice prompt
  • Appointments run out very quickly- on an average 10s window
    • Make sure you keep the browser window for TTP logged in and schedule it asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment