Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to notify upon check-in fails? #4

Closed
austinliuu opened this issue Jun 9, 2022 · 28 comments
Closed

Any way to notify upon check-in fails? #4

austinliuu opened this issue Jun 9, 2022 · 28 comments
Labels
enhancement New feature or request

Comments

@austinliuu
Copy link

Is there a way to let the user know if the automated check-in fails so they could do it manually ASAP?

@austinliuu austinliuu changed the title Any way to notify upon check-in fails Any way to notify upon check-in fails? Jun 10, 2022
@jdholtz
Copy link
Owner

jdholtz commented Jun 11, 2022

Yes, there are a few ways. I was planning on implementing that soon. Would you prefer a specific way of communication? Email, text message, webhooks, etc?

@austinliuu
Copy link
Author

Would recommend integrating with https://github.com/caronc/apprise or similar framework so you don't need to reinvent the wheel, but I think simple email should work too

@jdholtz
Copy link
Owner

jdholtz commented Jun 11, 2022

Apprise looks like a very good option. That’ll cover almost every option a user could want, so I’ll definitely go that route. Thanks!

@jdholtz jdholtz added the enhancement New feature or request label Jun 11, 2022
@jdholtz
Copy link
Owner

jdholtz commented Jun 12, 2022

I have implemented this feature on the notifications branch. Let me know if you have any issues if you choose to use it.

@austinliuu
Copy link
Author

austinliuu commented Jun 12, 2022

Awesome. I tested the branch and the test message works good, but notifications seem not to be triggered when there is a 400 Bad Request error.
(I don't have an upcoming trip for now[next flight in Aug😞] so I typed some random confirmation code and name, would that be considered as one of the "Error cases"? Can you try?)

Tested on my Raspberry pi 4 (Python 3.9.2, maybe it works on Python 3.10?)

user@raspberrypi:~/Desktop/auto-southwest-check-in $ python southwest.py ABSDW AW LD
https://github.com/electron/electron/releases/download/v17.0.0-beta.4/chromedriver-v17.0.0-beta.4-linux-arm64.zip
/home/user/.local/share/undetected_chromedriver/chromedriver
Traceback (most recent call last):
  File "/home/user/Desktop/auto-southwest-check-in/southwest.py", line 32, in <module>
    set_up(arguments)
  File "/home/user/Desktop/auto-southwest-check-in/southwest.py", line 23, in set_up
    account.get_checkin_info(confirmation_number)
  File "/home/user/Desktop/auto-southwest-check-in/lib/account.py", line 52, in get_checkin_info
    self._get_reservation_info(confirmation_number)
  File "/home/user/Desktop/auto-southwest-check-in/lib/account.py", line 62, in _get_reservation_info
    response = make_request("GET", site, self.headers, info)
  File "/home/user/Desktop/auto-southwest-check-in/lib/general.py", line 29, in make_request
    raise CheckInError(response.reason + " " + str(response.status_code))
lib.general.CheckInError: Bad Request 400

@austinliuu
Copy link
Author

austinliuu commented Jun 12, 2022

Might because of

class CheckInError(Exception):

has not been implemented

@jdholtz
Copy link
Owner

jdholtz commented Jun 12, 2022

Oh, there are two places it could raise that error and I only handled it for the actual check in part, not getting the flight times. That’s an easy fix.

Would it be useful to get a notification when it succeeds in scheduling a flight or only when it fails?

Also, that custom Exception class works fine. I only implemented it to have a custom error name for now.

@austinliuu
Copy link
Author

austinliuu commented Jun 13, 2022

👍
I would say for me notifications on both succeed and failed check-ins are useful, so user could understand what's going on. (More like how would you choose log level between INFO or ERROR)

@jdholtz
Copy link
Owner

jdholtz commented Jun 16, 2022

I added notifications to be sent when scheduling flights on both success and failure. I like the idea of having different levels to sending the notifications. I'll add that in the future as well.

@molmedo1
Copy link

molmedo1 commented Jun 27, 2022

script works but i cant figure out " python3 southwest.py --test-notifications" I get Invalid Arguments. Below is my config.json which i saved in "auto-southwest-check-in" folder:

{
"notification_urls": "pbul://o.MYTOKENOFCOURSE",
"notification_level": 1
}

I tested apprise and receive a pushbullet notification just fine. What am I missing here??

thanks,
mario

@jdholtz
Copy link
Owner

jdholtz commented Jun 27, 2022

Hey @molmedo1. Are you on the notifications branch in your repository? You can check by executing the command ‘git branch’ and seeing which branch is highlighted.

If you are, can you check the southwest.py file and see if there is a statement ‘if arguments[1] == “—test-notifications”’ on line 7?

@molmedo1
Copy link

Hey @molmedo1. Are you on the notifications branch in your repository? You can check by executing the command ‘git branch’ and seeing which branch is highlighted.

If you are, can you check the southwest.py file and see if there is a statement ‘if arguments[1] == “—test-notifications”’ on line 7?

ugh..i wasnt in notifications branch. Switched over and voila.....

$ python3 southwest.py --test-notifications
Sending test notifications...

Thanks JD!

@helpdeskdan
Copy link

$ cp config.example.json config.json
$ python3 southwest.py --test-notifications
Error in configuration file:
unsupported operand type(s) for |: 'type' and 'type'

That doesn't make sense

@helpdeskdan
Copy link

>>> from enum import IntEnum
>>> class NotificationLevel(IntEnum):
...     INFO = 1
...     ERROR = 2
... 
>>>
>>> notification_level = NotificationLevel.INFO
>>> notification_level
<NotificationLevel.INFO: 1>
>>> notification_level == 1
True
>>> notification_level == 2
False
>>> import json
>>> with open ("/home/dan/config.json") as file:
...      config = json.load(file)
... 
>>> config["notification_level"]
1
>>> isinstance(config["notification_level"], int)
True

It parses the info, why's it throw the darn exception? Drivin' me nuts!

@helpdeskdan
Copy link

Gah! It was staring me right in the face! If I weren't ill, I'd have gotten it earlier. Should be:

            #if not isinstance(self.notification_urls, list | str):
            if not isinstance(self.notification_urls, (list, str)):

@jdholtz
Copy link
Owner

jdholtz commented Jul 23, 2022

Hey @helpdeskdan. Are you using Python 3.10+? If you look at the note in the documentation for the isinstance function (https://docs.python.org/3/library/functions.html#isinstance), it says the function now supports Union types.

@helpdeskdan
Copy link

I figured it had to be something like that. Ubuntu 20.04 is still on 3.8.10. I'm baffled as to why Gmail striped the \n's (one big paragraph!), but your Python itself appears to work flawlessly with Apprise. Thanks a bunch!

@jdholtz
Copy link
Owner

jdholtz commented Jul 24, 2022

@helpdeskdan Thanks for mentioning that. I just looked into it and I found out that I can set a default formatting for Apprise to use which would correctly escape the newline characters. Unfortunately, there is a bug in Apprise which makes it not format correctly. It is already fixed, but not in the newest release, so I will wait for that to fix the formatting.

In the meantime, you can explicitly add &format=text to your Gmail URL for it to work correctly. Reference

@helpdeskdan
Copy link

That work around works well, thanks for that! I might recommend that minor change to isinstance for backward compatibility, as a many people do not run python 3.10 yet. Minor suggestion: Might be nice to have a separator - if somebody had 4 flights and 8 people, it might be a bit hard to read. Anyway, thanks again for your work!

@jdholtz
Copy link
Owner

jdholtz commented Jul 26, 2022

That would make sense to make it backwards compatible. I’ll adjust it and test to make sure everything runs correctly.

For the suggestion - Are you suggesting something like a blank line after each success/error message? That seems like a good thing to add for the user. Thanks!

@helpdeskdan
Copy link

Worked great for me, but I'd expect you would want to test it yourself.

As for separation, I mean something like this:

Person A Got B-1
Person B Got B-2
Person C Got B-3
Person D Got B-4
Person E Got B-5

Person A got B-10
Person B got B-11
Person C got B-12
Person D got B-13
Person E got B-14

Now, if you wanted to separate each section with "Flight Number XXXX" instead of \n, that would be even better, but a simple carriage return would make it more readable.

@jdholtz
Copy link
Owner

jdholtz commented Aug 14, 2022

Hey @helpdeskdan. I looked into making a separator when displaying the check-in results. I noticed that on success messages with multiple flights, they seem to be separated correctly already. When I'm testing, this is what I'm seeing with multiple flights:

Checking in to flight from <departure-airport> to <destination-airport> for <name>

Checking in to flight from <departure-airport> to <destination-airport> for <name> <--- flight 2, the same flight just a different reservation

Successfully checked in to flight from <departure-airport> to <destination-airport> for <name>!
Person A got B10
Person B got B11
Person C got B12

Successfully checked in to flight from <departure-airport> to <destination-airport> for <name>!
Person A got B18
Person B got B19

Is this what you mean when you want it to separate each section? I did notice it not separating correctly for error messages, but I'll fix that.

@austinliuu
Copy link
Author

Hi @jdholtz just would let you know the notification works good. Thanks for all the work!
1267E8F8-C46B-48BF-A23F-36C1289B90E2

@jdholtz
Copy link
Owner

jdholtz commented Aug 20, 2022

@austinliuu Glad to hear! Thanks for requesting this feature.

@helpdeskdan
Copy link

Hey @helpdeskdan. I looked into making a separator when displaying the check-in results. I noticed that on success messages with multiple flights, they seem to be separated correctly already. When I'm testing, this is what I'm seeing with multiple flights:

I don't see that at all, I see:

Successfully checked in to flight yada yada
Person A got yada
Person B got yada
yada yada big family
Person X got yaya
Person A got yada
Person B got yada
ect

Curious why you don't see the same. Oh well, not a huge problem. (I'm not exactly a frequent flier) Thanks again for the awesome project, was really handy when I they cancelled my flight three times in a row.

@jdholtz
Copy link
Owner

jdholtz commented Aug 20, 2022

Interesting. This is what is printed in the terminal, right?

@helpdeskdan
Copy link

Not sure, I just know that is how it was in the email

@jdholtz
Copy link
Owner

jdholtz commented Aug 21, 2022

Okay. I only tested what was printed to the console. You should be receiving only one notification per flight. I’ll look into that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants