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

Script Packt not working on the first time

VictorJ76 opened this issue · comments

Hello,

I'm using the lastest release and having an minor issue. every day I need to execute 2 times the packt-cli -gd command to get the ebook. You can see the error below.

You can ask me anything, logs, troubleshoot. I'm at your disposal.

root@computer:/opt/Packt-Publishing-Free-Learning# packt-cli -gd
[INFO] - JWT token has been fetched successfully!
[INFO] - Start grabbing ebook...
[INFO] - Getting your books data...
[INFO] - Books data has been successfully fetched.
[INFO] - Started solving ReCAPTCHA on Packt Free Learning website...
[INFO] - Waiting for completion of the 177670279 task...
[SUCCESS] - Solution found for 177670279 task.
[INFO] - A new Packt Free Learning ebook "Hands-On Penetration Testing on Windows" has been grabbed!
[INFO] - Title: "Hands-On Penetration Testing on Windows"
[INFO] - Downloading ebook: "Hands-On Penetration Testing on Windows" in pdf format...
[ERROR] - Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
[INFO] - Title: "Hands-On Penetration Testing on Windows"
[INFO] - Downloading ebook: "Hands-On Penetration Testing on Windows" in epub format...
[ERROR] - Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
[INFO] - 0 ebooks have been downloaded!
[SUCCESS] - Good, looks like all went well! :-)

root@computer:/opt/Packt-Publishing-Free-Learning# packt-cli -gd
[INFO] - JWT token has been fetched successfully!
[INFO] - Start grabbing ebook...
[INFO] - Getting your books data...
[INFO] - Books data has been successfully fetched.
[INFO] - You have already claimed Packt Free Learning "Hands-On Penetration Testing on Windows" offer.
[INFO] - Title: "Hands-On Penetration Testing on Windows"
[INFO] - Downloading ebook: "Hands-On Penetration Testing on Windows" in epub format...
[PROGRESS] - [################################################# ] 100.0% 
[SUCCESS] - Ebook "Hands-On Penetration Testing on Windows" in epub format downloaded successfully!
[INFO] - Title: "Hands-On Penetration Testing on Windows"
[INFO] - Downloading ebook: "Hands-On Penetration Testing on Windows" in pdf format...
[PROGRESS] - [################################################# ] 100.0% 
[SUCCESS] - Ebook "Hands-On Penetration Testing on Windows" in pdf format downloaded successfully!
[INFO] - 2 ebooks have been downloaded!
[SUCCESS] - Good, looks like all went well! :-)
root@computer:/opt/Packt-Publishing-Free-Learning# 

Looks like duplicate of #135. Unfortunately I couldn't help then, I'll think again what solution we could devise, but I cannot promise anything.

The (?) temporary solution may be cloning the repository, adding time.sleep(60) (maybe a few seconds will be enough, maybe waiting 60 seconds is not necessary) before download_products(api_client, download_directory, formats, [product_data], into_folder=False) in line 88 and installing the script from local repository (pip3 install -e .).

Note that I couldn't reproduce that issue before, so I'm only suggesting ranrinc's solution. Does his solution work for you?

Yes it looks like good now. I'll see in the future.

Thank you mjenczmyk ;)

Hello,
Sorry to bring this up again, but the time.sleep(60) didn't help. Tell me if you want logs or anything, thanks ;)

root@computer:~# packt-cli -gd --cfgpath /opt/Packt-Publishing-Free-Learning/configFile.cfg
[INFO] - JWT token has been fetched successfully!
[INFO] - Start grabbing ebook...
[INFO] - Getting your books data...
[INFO] - Books data has been successfully fetched.
[INFO] - Started solving ReCAPTCHA on Packt Free Learning website...
[INFO] - Waiting for completion of the 5200506 task...
[SUCCESS] - Solution found for 5200506 task.
[INFO] - A new Packt Free Learning ebook "Mastering Python for Networking and Security" has been grabbed!
[INFO] - Title: "Mastering Python for Networking and Security"
[INFO] - Downloading ebook: "Mastering Python for Networking and Security" in pdf format...
[ERROR] - Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
[INFO] - Title: "Mastering Python for Networking and Security"
[INFO] - Downloading ebook: "Mastering Python for Networking and Security" in epub format...
[ERROR] - Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
[INFO] - 0 ebooks have been downloaded!
[SUCCESS] - Good, looks like all went well! :-)

OK, I may have an idea - we can write a function executing another function and retrying a few times after some time if condition taking function result is not satisfied (and timeout after given time).

def wait_until(action, predicate, timeout, retry_after)

This way we could wrap (or decorate) lambda: get_product_download_urls(api_client, product_id) with wait_until, so it would wait as long as it's needed. I'll write that code someday (maybe next week, I cannot promise it'll be this one) and let you know so you can test it.

It's been a while since Packt doesnt provide other formats than html (kinda bookdown). My question is that this script allows downloading books in this format too?

Thanks

@danmaxis I've moved the discussion to another issue, as it's an off topic here.

@luk6xff Let's leave it open for a bit longer, I've an idea how to solve this problem (although I don't have any idea why I don't encounter this problem).

@VictorJ76 Please try installing script with pip install git+https://github.com/luk6xff/Packt-Publishing-Free-Learning.git@timeout command and see if it helps. If not we may try to increase the timeout value.

If that helps install script with pip install packt and confirm that it does not work - that way we'll make sure whether #166 helps.

@VictorJ76 Please try installing script with pip install git+https://github.com/luk6xff/Packt-Publishing-Free-Learning.git@timeout command and see if it helps. If not we may try to increase the timeout value.

That has worked for me. Excellent!

Glad I could help. Writing this wait_for_computation decorator was interesting itself, I haven't wrote in Python for some time until this pull request ;)

I'll merge it, release the new version and close the issue.

Resolved by #166.