Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding feature to look for a specific date #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"current_interview_date_str": "",
"enrollment_location_id": "",
"logfile": "",
"number_of_appointments_to_query": "5",

"email_from": "",
"email_to": [""],
Expand All @@ -11,7 +12,10 @@
"email_password": "",

"__comment": "Below are optional:",
"use_gmail": true,

"specific_date_wanted": false,
"exact_date_wanted": "",
"use_gmail": false,
"gmail_password": "",
"no_email": false,
"no_spamming": true,
Expand Down
31 changes: 22 additions & 9 deletions goes-notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<p>Your current appointment is on %s</p>
<p>If this sounds good, please sign in to https://ttp.cbp.dhs.gov/ to reschedule.</p>
"""
GOES_URL_FORMAT = 'https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit=3&locationId={0}&minimum=1'
GOES_URL_FORMAT = 'https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit={0}&locationId={1}&minimum=1'

def notify_send_email(dates, current_apt, settings, use_gmail=False):
sender = settings.get('email_from')
Expand Down Expand Up @@ -107,21 +107,34 @@ def notify_sms(settings, dates):
def main(settings):
try:
# obtain the json from the web url
data = requests.get(GOES_URL_FORMAT.format(settings['enrollment_location_id'])).json()
data = requests.get(GOES_URL_FORMAT.format(settings["number_of_appointments_to_query"], settings['enrollment_location_id'])).json()

# parse the json
if not data:
logging.info('No tests available.')
return

current_apt = datetime.strptime(settings['current_interview_date_str'], '%B %d, %Y')

dates = []
for o in data:
if o['active']:
dt = o['startTimestamp'] #2017-12-22T15:15
dtp = datetime.strptime(dt, '%Y-%m-%dT%H:%M')
if current_apt > dtp:
dates.append(dtp.strftime('%A, %B %d @ %I:%M%p'))

if settings['specific_date_wanted']:
current_apt = datetime.strptime(settings['exact_date_wanted'], '%B %d, %Y')
for o in data:
if o['active']:
dt = o['startTimestamp'] #2017-12-22T15:15
dtp = datetime.strptime(dt, '%Y-%m-%dT%H:%M')
if current_apt.date() == dtp.date():
dates.append(dtp.strftime('%A, %B %d @ %I:%M%p'))


else:
current_apt = datetime.strptime(settings['current_interview_date_str'], '%B %d, %Y')
for o in data:
if o['active']:
dt = o['startTimestamp'] #2017-12-22T15:15
dtp = datetime.strptime(dt, '%Y-%m-%dT%H:%M')
if current_apt > dtp:
dates.append(dtp.strftime('%A, %B %d @ %I:%M%p'))

if not dates:
return
Expand Down