packt-cli / Packt-Publishing-Free-Learning

Scripts that automatically claim and download free daily eBooks from https://www.packtpub.com/packt/offers/free-learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle case when there is no Free Learning offer

mjenczmyk opened this issue · comments

2019-12-19 02:30:01,780 - utils.anticaptcha - [INFO] - Started solving ReCAPTCHA for https://www.packtpub.com/ website...
2019-12-19 02:30:02,322 - utils.anticaptcha - [INFO] - Waiting for completion of the 784702082 task...
2019-12-19 02:30:38,246 - utils.anticaptcha - [SUCCESS] - Solution found for 784702082 task.
2019-12-19 02:30:38,880 - api - [INFO] - JWT token has been fetched successfully!
2019-12-19 02:30:38,880 - claimer - [INFO] - Start grabbing ebook...
2019-12-19 02:30:39,119 - packtPublishingFreeEbook - [ERROR] - Exception occurred not enough values to unpack (expected 1, got 0)

As probably everybody knows there is an exception raised when there is no Free Learning offer - we should handle it so the script will fail gracefully and with meaningful message.

Hello
I have created pull request #189 (my first one...) in order to handle it.
I have tried it past days, it seems OK (when there is an offer and when there isn't).
Hope this helps, regards
Laurent

Thanks, I tried to solve it myself last week, but I didn't finish it though. I see that raising the exception may be easy to handle, I tried it another way.

Sorry for using french, I was handling a meeting while writing down the code.
Now code is in english and pylama errors free.
Using the existing exception, you receive a message "Today's free Packt ebook grabbing has failed with exception: : There is no Free Learning offer right now". Not ideal, but meaningfull while reading your email.
I am neither an expert in python nor in git, please forgive me if I have done things the wrong way.
Thanks for all your work, regards
Laurent

No problem, there is a time to learn. I've added two comments, but it looks much better now ;)

Thanks for your pull request, now it's much clearer for the user to see what happened when script failed due to no Free Learning offer.