mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-10 21:33:18 +00:00
Refactoring to support multiple notifications
This commit is contained in:
20
checkin.py
20
checkin.py
@@ -30,7 +30,7 @@ import time
|
|||||||
CHECKIN_EARLY_SECONDS = 5
|
CHECKIN_EARLY_SECONDS = 5
|
||||||
|
|
||||||
|
|
||||||
def schedule_checkin(flight_time, number, first, last, email, mobile):
|
def schedule_checkin(flight_time, number, first, last, notify=[]):
|
||||||
checkin_time = flight_time - timedelta(days=1)
|
checkin_time = flight_time - timedelta(days=1)
|
||||||
current_time = datetime.now(utc).astimezone(get_localzone())
|
current_time = datetime.now(utc).astimezone(get_localzone())
|
||||||
# check to see if we need to sleep until 24 hours before flight
|
# check to see if we need to sleep until 24 hours before flight
|
||||||
@@ -46,13 +46,10 @@ def schedule_checkin(flight_time, number, first, last, email, mobile):
|
|||||||
for flight in data['flights']:
|
for flight in data['flights']:
|
||||||
for doc in flight['passengers']:
|
for doc in flight['passengers']:
|
||||||
print("{} got {}{}!".format(doc['name'], doc['boardingGroup'], doc['boardingPosition']))
|
print("{} got {}{}!".format(doc['name'], doc['boardingGroup'], doc['boardingPosition']))
|
||||||
if email:
|
southwest.send_notification(data, notify)
|
||||||
southwest.send_notification(data, emailaddr=email)
|
|
||||||
elif mobile:
|
|
||||||
southwest.send_notification(data, mobilenum=mobile)
|
|
||||||
|
|
||||||
|
|
||||||
def auto_checkin(reservation_number, first_name, last_name, email=None, mobile=None):
|
def auto_checkin(reservation_number, first_name, last_name, notify=[]):
|
||||||
body = southwest.lookup_existing_reservation(reservation_number, first_name, last_name)
|
body = southwest.lookup_existing_reservation(reservation_number, first_name, last_name)
|
||||||
|
|
||||||
# Get our local current time
|
# Get our local current time
|
||||||
@@ -72,7 +69,7 @@ def auto_checkin(reservation_number, first_name, last_name, email=None, mobile=N
|
|||||||
# found a flight for checkin!
|
# found a flight for checkin!
|
||||||
print("Flight information found, departing {} at {}".format(airport, date.strftime('%b %d %I:%M%p')))
|
print("Flight information found, departing {} at {}".format(airport, date.strftime('%b %d %I:%M%p')))
|
||||||
# Checkin with a thread
|
# Checkin with a thread
|
||||||
t = Thread(target=schedule_checkin, args=(date, reservation_number, first_name, last_name, email, mobile))
|
t = Thread(target=schedule_checkin, args=(date, reservation_number, first_name, last_name, notify))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
@@ -97,8 +94,15 @@ if __name__ == '__main__':
|
|||||||
email = arguments['--email']
|
email = arguments['--email']
|
||||||
mobile = arguments['--mobile']
|
mobile = arguments['--mobile']
|
||||||
|
|
||||||
|
# build out notifications
|
||||||
|
notifications = []
|
||||||
|
if email is not None:
|
||||||
|
notifications.append({'mediaType': 'EMAIL', 'emailAddress': email})
|
||||||
|
if mobile is not None:
|
||||||
|
notifications.append({'mediaType': 'SMS', 'phoneNumber': mobile})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
auto_checkin(reservation_number, first_name, last_name, email, mobile)
|
auto_checkin(reservation_number, first_name, last_name, notifications)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Ctrl+C detected, canceling checkin")
|
print("Ctrl+C detected, canceling checkin")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
15
southwest.py
15
southwest.py
@@ -52,17 +52,16 @@ def checkin(number, first, last):
|
|||||||
print("Attempting check-in...")
|
print("Attempting check-in...")
|
||||||
return safe_request(url, info_needed['body'])['checkInConfirmationPage']
|
return safe_request(url, info_needed['body'])['checkInConfirmationPage']
|
||||||
|
|
||||||
def send_notification(checkindata, emailaddr=None, mobilenum=None):
|
def send_notification(checkindata, notify):
|
||||||
|
if len(notify) < 1:
|
||||||
|
return
|
||||||
info_needed = checkindata['_links']['boardingPasses']
|
info_needed = checkindata['_links']['boardingPasses']
|
||||||
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
||||||
mbpdata = safe_request(url, info_needed['body'])
|
mbpdata = safe_request(url, info_needed['body'])
|
||||||
info_needed = mbpdata['checkInViewBoardingPassPage']['_links']
|
info_needed = mbpdata['checkInViewBoardingPassPage']['_links']
|
||||||
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
||||||
if emailaddr:
|
|
||||||
info_needed['body']['mediaType'] = 'EMAIL'
|
|
||||||
info_needed['body']['emailAddress'] = emailaddr
|
|
||||||
if mobilenum:
|
|
||||||
info_needed['body']['mediaType'] = 'SMS'
|
|
||||||
info_needed['body']['phoneNumber'] = mobilenum
|
|
||||||
print("Attempting to send boarding pass...")
|
print("Attempting to send boarding pass...")
|
||||||
safe_request(url, info_needed['body'])
|
body = info_needed['body']
|
||||||
|
for n in notify:
|
||||||
|
body.update(n)
|
||||||
|
safe_request(url, body)
|
||||||
|
|||||||
Reference in New Issue
Block a user