mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-06 01:13:19 +00:00
Abstracting out json page loads
This commit is contained in:
23
southwest.py
23
southwest.py
@@ -43,23 +43,28 @@ class Reservation():
|
|||||||
# Ignore responses with no json data in body
|
# Ignore responses with no json data in body
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def load_json_page(self, url, body=None):
|
||||||
|
data = self.safe_request(url, body)
|
||||||
|
for k, v in list(data.items()):
|
||||||
|
if k.endswith("Page"):
|
||||||
|
return v
|
||||||
|
|
||||||
|
def with_suffix(self, uri):
|
||||||
|
return "{}{}{}?first-name={}&last-name={}".format(BASE_URL, uri, self.number, self.first, self.last)
|
||||||
|
|
||||||
def lookup_existing_reservation(self):
|
def lookup_existing_reservation(self):
|
||||||
# Find our existing record
|
# Find our existing record
|
||||||
url = "{}mobile-misc/v1/mobile-misc/page/view-reservation/{}?first-name={}&last-name={}".format(BASE_URL, self.number, self.first, self.last)
|
return self.load_json_page(self.with_suffix("mobile-misc/v1/mobile-misc/page/view-reservation/"))
|
||||||
data = self.safe_request(url)
|
|
||||||
return data['viewReservationViewPage']
|
|
||||||
|
|
||||||
def get_checkin_data(self):
|
def get_checkin_data(self):
|
||||||
url = "{}mobile-air-operations/v1/mobile-air-operations/page/check-in/{}?first-name={}&last-name={}".format(BASE_URL, self.number, self.first, self.last)
|
return self.load_json_page(self.with_suffix("mobile-air-operations/v1/mobile-air-operations/page/check-in/"))
|
||||||
data = self.safe_request(url)
|
|
||||||
return data['checkInViewReservationPage']
|
|
||||||
|
|
||||||
def checkin(self):
|
def checkin(self):
|
||||||
data = self.get_checkin_data()
|
data = self.get_checkin_data()
|
||||||
info_needed = data['_links']['checkIn']
|
info_needed = data['_links']['checkIn']
|
||||||
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
||||||
print("Attempting check-in...")
|
print("Attempting check-in...")
|
||||||
confirmation = self.safe_request(url, info_needed['body'])['checkInConfirmationPage']
|
confirmation = self.load_json_page(url, info_needed['body'])
|
||||||
if len(self.notifications) > 0:
|
if len(self.notifications) > 0:
|
||||||
self.send_notification(confirmation)
|
self.send_notification(confirmation)
|
||||||
return confirmation
|
return confirmation
|
||||||
@@ -67,8 +72,8 @@ class Reservation():
|
|||||||
def send_notification(self, checkindata):
|
def send_notification(self, checkindata):
|
||||||
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 = self.safe_request(url, info_needed['body'])
|
mbpdata = self.load_json_page(url, info_needed['body'])
|
||||||
info_needed = mbpdata['checkInViewBoardingPassPage']['_links']
|
info_needed = mbpdata['_links']
|
||||||
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
|
||||||
print("Attempting to send boarding pass...")
|
print("Attempting to send boarding pass...")
|
||||||
body = info_needed['body']
|
body = info_needed['body']
|
||||||
|
|||||||
Reference in New Issue
Block a user