mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-06 01:13:19 +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]
|
||||
first_name = sys.argv[2]
|
||||
last_name = sys.argv[3]
|
||||
checkin_early_seconds = 5 * 60
|
||||
checkin_interval_seconds = 10
|
||||
|
||||
|
||||
# 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)
|
||||
@@ -45,30 +48,36 @@ else:
|
||||
|
||||
# Wait until checkin time
|
||||
if date > tomorrow:
|
||||
delta = (date-tomorrow).total_seconds()
|
||||
delta = (date-tomorrow).total_seconds() - checkin_early_seconds
|
||||
m, s = divmod(delta, 60)
|
||||
h, m = divmod(m, 60)
|
||||
print("Too early to check in. Waiting {} hours, {} minutes, {} seconds".format(trunc(h), trunc(m), s))
|
||||
time.sleep(delta)
|
||||
|
||||
print("Attempting check-in...")
|
||||
|
||||
# Get our passengers to get boarding passes for
|
||||
passengers = []
|
||||
for passenger in body['passengers']:
|
||||
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'
|
||||
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':
|
||||
print(body['message'])
|
||||
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']))
|
||||
while not success:
|
||||
|
||||
print("Attempting check-in...")
|
||||
r = requests.post(url, headers=headers, json={'names': passengers})
|
||||
body = r.json()
|
||||
|
||||
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