Fffrank / southwest-alerts

MIT License
19 stars 9 forks source link

Fails with companion tickets #9

Open hoopsbwc34 opened 3 years ago

hoopsbwc34 commented 3 years ago

When you have a companion ticket linked to the ticket, you aren't able to change the flight (southwest posts a message that says a companion ticket is linked and you must cancel that ticket first). This causes the script to fail on line 69 of southwest.py:

INFO:root:Attempt 1 at capturing headers....
[I:pyppeteer.launcher] Browser listening on: ws://127.0.0.1[snipped]
[I:pyppeteer.launcher] terminate chrome process...
INFO:root:Detected account XXXXX and captured headers.
[I:pyppeteer.launcher] terminate chrome process...
.INFO:root:Processing: XXXXXX
.Traceback (most recent call last):
  File "app.py", line 285, in <module>
    check_for_price_drops(user.username, user.password, user.email, user.headers, user.cookies, user.account)
  File "app.py", line 143, in check_for_price_drops
    cancellation_details = southwest.get_cancellation_details(record_locator, passenger['first-name'], passenger['last-name'])
  File "/path/to/script/southwest-alerts/southwestalerts/southwest.py", line 69, in get_cancellation_details
    token=temp['viewReservationViewPage']['_links']['cancelBound']['query']['passenger-search-token']
TypeError: 'NoneType' object is not subscriptable

It would be nice if the script continued on to the next confirmation code instead of dying as I have other reservations in the future that I'd like to check.

hoopsbwc34 commented 3 years ago

Here's what I did to fix the problem above, let me know if you want a PR:

        temp = self._session.get(url)
        # check if there is a greyboxmessage warning for companion or other issue
        if not (temp['viewReservationViewPage']['greyBoxMessage'] is None):
            return None
        url = '/api/mobile-air-booking/v1/mobile-air-booking/page/flights/cancel-bound/{record_locator}?passenger-search-token={token}'.format(
            record_locator=record_locator,
            token=temp['viewReservationViewPage']['_links']['cancelBound']['query']['passenger-search-token']
        )

And the corresponding continue to the for loop in app.py:


            # try:
            cancellation_details = southwest.get_cancellation_details(record_locator, passenger['first-name'], passenger['last-name'])
            if cancellation_details is None:
                continue
Fffrank commented 3 years ago

I don't currently have a companion so haven't been able to test, but would love if you could try to push this fix! Thanks!

hoopsbwc34 commented 3 years ago

I'll have to cherry pick cause I've got a lot of differences in my code (using Twilio for SMS notifications and config.ini instead of system variables for my southwest login info) so it may take me a bit, but I'll create a pull request here soon!

r1rider01 commented 2 years ago

I don't think this is related directly to the companion pass. I get the same error for a non-companion pass flight.

Hoopsbwc34, i'd love to see your changes and integration for Twilio thou!