mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-27 21:33:14 +00:00
Added early checkin and retry - Not tested :(
This commit is contained in:
35
checkin.py
35
checkin.py
@@ -15,6 +15,9 @@ headers = {'Host': 'mobile.southwest.com', 'Content-Type': 'application/vnd.swac
|
|||||||
reservation_number = sys.argv[1]
|
reservation_number = sys.argv[1]
|
||||||
first_name = sys.argv[2]
|
first_name = sys.argv[2]
|
||||||
last_name = sys.argv[3]
|
last_name = sys.argv[3]
|
||||||
|
checkin_early_seconds = 5 * 60
|
||||||
|
checkin_interval_seconds = 10
|
||||||
|
|
||||||
|
|
||||||
# Find our existing record
|
# Find our existing record
|
||||||
url = "https://mobile.southwest.com/api/extensions/v1/mobile/reservations/record-locator/{}?first-name={}&last-name={}".format(reservation_number, first_name, last_name)
|
url = "https://mobile.southwest.com/api/extensions/v1/mobile/reservations/record-locator/{}?first-name={}&last-name={}".format(reservation_number, first_name, last_name)
|
||||||
@@ -45,30 +48,36 @@ else:
|
|||||||
|
|
||||||
# Wait until checkin time
|
# Wait until checkin time
|
||||||
if date > tomorrow:
|
if date > tomorrow:
|
||||||
delta = (date-tomorrow).total_seconds()
|
delta = (date-tomorrow).total_seconds() - checkin_early_seconds
|
||||||
m, s = divmod(delta, 60)
|
m, s = divmod(delta, 60)
|
||||||
h, m = divmod(m, 60)
|
h, m = divmod(m, 60)
|
||||||
print("Too early to check in. Waiting {} hours, {} minutes, {} seconds".format(trunc(h), trunc(m), s))
|
print("Too early to check in. Waiting {} hours, {} minutes, {} seconds".format(trunc(h), trunc(m), s))
|
||||||
time.sleep(delta)
|
time.sleep(delta)
|
||||||
|
|
||||||
print("Attempting check-in...")
|
|
||||||
|
|
||||||
# Get our passengers to get boarding passes for
|
# Get our passengers to get boarding passes for
|
||||||
passengers = []
|
passengers = []
|
||||||
for passenger in body['passengers']:
|
for passenger in body['passengers']:
|
||||||
passengers.append({'firstName': passenger['secureFlightName']['firstName'], 'lastName': passenger['secureFlightName']['lastName']})
|
passengers.append({'firstName': passenger['secureFlightName']['firstName'], 'lastName': passenger['secureFlightName']['lastName']})
|
||||||
|
|
||||||
# Check in
|
# Setting up request
|
||||||
headers['Content-Type'] = 'application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json'
|
headers['Content-Type'] = 'application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json'
|
||||||
url = "https://mobile.southwest.com/api/extensions/v1/mobile/reservations/record-locator/{}/boarding-passes".format(reservation_number)
|
url = "https://mobile.southwest.com/api/extensions/v1/mobile/reservations/record-locator/{}/boarding-passes".format(reservation_number)
|
||||||
r = requests.post(url, headers=headers, json={'names': passengers})
|
|
||||||
|
|
||||||
body = r.json()
|
success = False
|
||||||
|
|
||||||
if 'httpStatusCode' in body and body['httpStatusCode'] == 'FORBIDDEN':
|
while not success:
|
||||||
print(body['message'])
|
|
||||||
else:
|
print("Attempting check-in...")
|
||||||
# Spit out info about boarding number
|
r = requests.post(url, headers=headers, json={'names': passengers})
|
||||||
for checkinDocument in body['passengerCheckInDocuments']:
|
body = r.json()
|
||||||
for doc in checkinDocument['checkinDocuments']:
|
|
||||||
print("You got {}{}!".format(doc['boardingGroup'], doc['boardingGroupNumber']))
|
if 'httpStatusCode' in body and body['httpStatusCode'] == 'FORBIDDEN':
|
||||||
|
print(body['message'])
|
||||||
|
print("Waiting {} seconds before retrying...".format(checkin_interval_seconds))
|
||||||
|
time.sleep(checkin_interval_seconds)
|
||||||
|
else:
|
||||||
|
# Spit out info about boarding number
|
||||||
|
for checkinDocument in body['passengerCheckInDocuments']:
|
||||||
|
for doc in checkinDocument['checkinDocuments']:
|
||||||
|
print("You got {}{}!".format(doc['boardingGroup'], doc['boardingGroupNumber']))
|
||||||
|
success = True
|
||||||
|
|||||||
Reference in New Issue
Block a user