diff --git a/.codeclimate.yml b/.codeclimate.yml index 4fe2e44..aab99e8 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -4,4 +4,7 @@ plugins: enabled: true checks: E501: - enabled: false \ No newline at end of file + enabled: false + argument-count: + config: + threshold: 5 diff --git a/checkin.py b/checkin.py index 739c833..bbebbf0 100755 --- a/checkin.py +++ b/checkin.py @@ -50,8 +50,8 @@ def schedule_checkin(flight_time, reservation): print("{} got {}{}!".format(doc['name'], doc['boardingGroup'], doc['boardingPosition'])) -def auto_checkin(reservation_number, first_name, last_name, notify=[]): - r = Reservation(reservation_number, first_name, last_name, notify) +def auto_checkin(reservation_number, first_name, last_name, notify=[], verbose=False): + r = Reservation(reservation_number, first_name, last_name, notify, verbose) body = r.lookup_existing_reservation() # Get our local current time @@ -89,12 +89,13 @@ def auto_checkin(reservation_number, first_name, last_name, notify=[]): if __name__ == '__main__': - arguments = docopt(__doc__, version='Southwest Checkin 1') + arguments = docopt(__doc__, version='Southwest Checkin 2') reservation_number = arguments['CONFIRMATION_NUMBER'] first_name = arguments['FIRST_NAME'] last_name = arguments['LAST_NAME'] email = arguments['--email'] mobile = arguments['--mobile'] + verbose = arguments['--verbose'] # build out notifications notifications = [] @@ -104,7 +105,7 @@ if __name__ == '__main__': notifications.append({'mediaType': 'SMS', 'phoneNumber': mobile}) try: - auto_checkin(reservation_number, first_name, last_name, notifications) + auto_checkin(reservation_number, first_name, last_name, notifications, verbose) except KeyboardInterrupt: print("Ctrl+C detected, canceling checkin") sys.exit() diff --git a/southwest/southwest.py b/southwest/southwest.py index 83da655..d64c0fb 100644 --- a/southwest/southwest.py +++ b/southwest/southwest.py @@ -1,5 +1,6 @@ from time import sleep import requests +import json import sys import uuid @@ -10,11 +11,12 @@ MAX_ATTEMPTS = 40 class Reservation(): - def __init__(self, number, first, last, notifications=[]): + def __init__(self, number, first, last, notifications=[], verbose=False): self.number = number self.first = first self.last = last self.notifications = notifications + self.verbose = verbose @staticmethod def generate_headers(): @@ -45,11 +47,18 @@ class Reservation(): data = r.json() if 'httpStatusCode' in data and data['httpStatusCode'] in ['NOT_FOUND', 'BAD_REQUEST', 'FORBIDDEN']: attempts += 1 - print(data['message']) + if not self.verbose: + print(data['message']) + else: + print(r.headers) + print(json.dumps(data, indent=2)) if attempts > MAX_ATTEMPTS: sys.exit("Unable to get data, killing self") sleep(CHECKIN_INTERVAL_SECONDS) continue + if self.verbose: + print(r.headers) + print(json.dumps(data, indent=2)) return data except ValueError: # Ignore responses with no json data in body