Skip to main content

Free Learning Packt Publishing script

packt-cli is a Python script that allows to automatically grab and download a daily Free Learning Packt ebook from https://www.packtpub.com/packt/offers/free-learning. You can also use it to download already claimed ebooks from your Packt account.

The script uses anti-captcha.com service to bypass the Recaptcha captcha to function fully automatically. Anti Captcha employs people to solve captcha tests. The service costs about $2 per thousand captcha test, allowing you to operate for a few dollars over the years.

Docker images are provided at Docker Hub. Installation and usage are described here.

Installation

To install current version of script simply run

pip3 install packt --upgrade

You may want to install it inside new virtualenv.

Usage

The packt-cli script might be executed with several optional arguments.

  • Option -g [--grab] - claims (grabs) a daily eBook into your account
packt-cli -g
  • Option -gd [--grabd] - claims (grabs) a daily ebook and downloads the title afterwards to the location specified under [download_folder_path] field (configFile.cfg file)
packt-cli -gd
  • Option -da [--dall] - downloads all ebooks from your account
packt-cli -da
  • Option -sgd [--sgd] - claims and uploads a book to [gdFolderName] folder onto Google Drive (more about that in Google Drive API Setup section)
packt-cli -sgd
  • Option -m [--mail] - claims and sends an email with the newest book in PDF format (and MOBI if is also downloaded; see mail options confguration under [MAIL] path in configFile.cfg)
packt-cli -m
  • SubOption -sm [--status_mail] - sends fail report email whether script execution was successful
packt-cli -gd -sm
  • SubOption -f [--folder] - downloads an ebook into a created folder, named as ebook's title
packt-cli -gd -f
  • SubOption -c [--cfgpath] - selects folder where config file can be found (default: cwd)
packt-cli -gd -c /home/usr/

Example

Download all ebooks in all available formats (pdf, epub, mobi) with zipped source code file from your Packt account.

To download all ebooks in all available formats from your Packt account, you have to prepare your config file as shown below:

[LOGIN_DATA]
email: youremail@youremail.com
password: yourpassword

[DOWNLOAD_DATA]
download_folder_path: C:\Users\me\Desktop\myEbooksFromPackt
download_formats: pdf, epub, mobi, code

[GOOGLE_DRIVE_DATA]
gd_folder_name: PACKT_EBOOKS

run:

  packt-cli -da

Scheduled script execution setup

Debian

On Debian (and any Debian-based Linux distribution) you may use cron job to schedule script execution. To do this run crontab -e and add the following line to crontab file.

0 12 * * * path/to/virtualenv/bin/packt-cli -gd > path/to/log/file 2>&1

Adjust execution time and paths according to your setup. To verify if cron executes the script as expected, run

$ sudo grep CRON /var/log/syslog

Windows

schtasks.exe setup (more info: https://technet.microsoft.com/en-us/library/cc725744.aspx) :

To create the task that will be called at 12:00 everyday, run the following command in cmd (modify all paths according to your setup):

schtasks /create /sc DAILY /tn "grabEbookFromPacktTask" /tr "C:\Users\me\Desktop\GrabPacktFreeBook\grabEbookFromPacktTask.bat" /st 12:00

To check if the "grabEbookFromPacktTask" has been added to all scheduled tasks on your computer:

schtasks /query

To run the task manually:

schtasks /run /tn "grabEbookFromPacktTask"

To delete the task:

schtasks /delete /tn "grabEbookFromPacktTask"

If you want to log all downloads add -l switch to grabEbookFromPacktTask i.e.

schtasks /create /sc DAILY /tn "grabEbookFromPacktTask" /tr "C:\Users\me\Desktop\GrabPacktFreeBook\grabEbookFromPacktTask.bat -l" /st 12:00

If you want to additionaly make command line windows stay open after download add -p switch i.e.

schtasks /create /sc DAILY /tn "grabEbookFromPacktTask" /tr "C:\Users\me\Desktop\GrabPacktFreeBook\grabEbookFromPacktTask.bat -l -p" /st 12:00

Google Drive API Setup

Full info about the Google Drive Python API can be found here.

WARNING: if you're upgrading from v1.10.5 or older you may need to reauthenticate!

  1. Turn on the Google Drive API
  • Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
  • On the Add credentials to your project page, click the Cancel button.
  • At the top of the page, select the OAuth consent screen tab. Select an email address, enter a product name if not already set, and click the Save button.
  • Select the Credentials tab, click the Create credentials button and select OAuth client ID.
  • Select the application type Other, enter the name GoogleDriveManager, and click the Create button.
  • Click OK to dismiss the resulting dialog.
  • Click the file_download (Download JSON) button to the right of the client ID.
  • Move this file next to the config file and rename it to client_secret.json.
  1. Create credentials folder:
  • Simply, just fire up the script with -sgd argument; During first launch you will see a prompt in your browser asking for permissions, click then allow
packt-cli -sgd
  • Or if you're unable to launch browser locally (e.g. you're connecting through SSH without X11 forwarding) use this command once, follow instructions and give permission and later you can use normal command (without --noauth_local_webserver).
packt-cli -c /path/to/config/file.cfg -sgd --noauth_local_webserver

The command parameters number and their order is important!

  1. Already done!
  • Run the same command as above to claim and upload the eBook to Google Drive.

In case of any questions feel free to ask, happy grabbing!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packt-1.10.8.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packt-1.10.8-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file packt-1.10.8.tar.gz.

File metadata

  • Download URL: packt-1.10.8.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for packt-1.10.8.tar.gz
Algorithm Hash digest
SHA256 06312b7e762475a7ebc7cab20e8a28bc274c5d99e25055634cf9701058a572a5
MD5 54c1a9e685470bb7f0f242925ba486d4
BLAKE2b-256 05ee3b873a012ca012dc96e8966b416a71e3c4820664551de1df2257e4ceef8a

See more details on using hashes here.

File details

Details for the file packt-1.10.8-py3-none-any.whl.

File metadata

  • Download URL: packt-1.10.8-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for packt-1.10.8-py3-none-any.whl
Algorithm Hash digest
SHA256 de3a57eefc4c65a4baa976839933f2aa888a697bac352dc1ee5933c67a690b31
MD5 2bfdf9540fbe09840a9d6a72dd346910
BLAKE2b-256 e172eeb007f6b46877f5b5d7b977a915ef9f005fe07a3d0d00f4b9c895da5baa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.10.8 This release

2 files

1.10.6

2 files

1.10.5

2 files

1.10.4

2 files

1.10.3

2 files

1.10.2

2 files

1.10.0

2 files

1.9.1

1 file

1.9.0

1 file

1.8.10

1 file

1.8.9

1 file

1.8.8

1 file

1.8.7

1 file

1.8.6

1 file

1.8.5

1 file

1.8.3

1 file

1.8.2

1 file

1.8.1

1 file

1.8.0

1 file

1.7.0

1 file

1.6.0

1 file

1.5.8

1 file

1.5.7

1 file

1.5.6

1 file

1.5.5

1 file

1.5.4

1 file

1.5.3

1 file

1.5.2

1 file

1.5.1

1 file

1.5.0

1 file

1.4.3

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

2 files

1.3.0

1 file

1.2.2

1 file

1.2.1

1 file

1.2.0

1 file

1.1.0

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page