Last active
September 11, 2022 23:39
-
-
Save pradeepbn/9daebb1c4bd08a8298c71c8465a50929 to your computer and use it in GitHub Desktop.
GE appointment schedule checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script works on macOS.
python 3
pip3 install requests
python3 check_ge_appt_schedule.py
on a terminal