Skip to content

model-map/wikipedia-to-kindle-azw3-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wikipedia-to-kindle-azw3-pdf

A bash script to send wikipedia articles to kindle as azw3. Also downloads the pdf to your current directory.

Setup

(Note: If you only want to download wikipedia articles as pdf and don't care about sending them to your kindle, skip step 1,2,3,4 and go directly to step 5.)

Before we can begin executing the script we need to make a few changes on our end.

  1. Get Google app password
    This is required for Google to allow your app to send mail via its smtp server.
    Since we're sending mail to your kindle, please make sure the email address is in kindle's approved email list.

    (Note: The following guide follows Gmail configuration. If you're using another email provider, please lookup their smtp configuration)

  2. Open '/etc/ssmtp/ssmtp.conf' and add the following entry:
    (Create the dir and file if they don't exist.)

UseSTARTTLS=YES
FromLineOverride=YES
root=admin@example.com
mailhub=smtp.gmail.com:587
AuthUser=username@gmail.com
AuthPass=password

Replace AuthUser and Authpass with your kindle-approved gmail and app-password respectively.

  1. Installing ssmtp and mpack
    On ubuntu:
sudo apt-get install ssmtp
sudo apt-get install mpack
  1. There are two methods to use the script.

    4.1. executing the bash script
    4.2. setting alias in ~/.bashrc

    • Executing bash script

      • Download wikipedia-to-azw3.sh file from the github repo
      • nano ./wikipedia-to-azw3.sh and change mail@kindle.com to your kindle email.
      • chmod +x ./wikipedia-to-azw3.sh
      • use by executing ./wikipedia-to-azw3.sh [article-name] for example ./wikipedia-to-azw3.sh computer_science
      • It is also possible to download multiple files. Just mention article names in succession. For example
        ./wikipedia-to-azw3.sh computer_science algorithm life death will download wikipedia articles for computer_science, algorithm, life, death and send them to your kindle device.
    • Setting alias in ~/.bashrc

      • nano ~/.bashrc
      • Add alias [alias]='function _wikipdf() { local words=($@); for word in "${words[@]}"; do wget "en.wikipedia.org/api/rest_v1/page/pdf/$word" && mv "./$word" "./$word.pdf" && mpack -s "convert" -a "./$word.pdf" mail@kindle.com; done; }; _wikipdf'
        Replace [alias] and mail with an alias and your kindle email respectively.

      (I personally recommend 4.2. since it allows the command to be executed from anywhere as opposed to the script method.)

  2. Optionally if you only want to download wikipedia articles as pdf without wanting to send it to kindle you could set
    alias [alias]='function _wikipdf() { wget "en.wikipedia.org/api/rest_v1/page/pdf/$1" && mv ./$1 ./$1.pdf; }; _wikipdf' to your ~/.bashrc.

Usage

Depending on the execution method chosen (either 4.1 or 4.2 from above) the articles can be sent by using the command
./wikipedia-to-kindle.sh article1 article2 article3
or
[alias] article1 article2 article3

So, for example: ./wikipedia-to-kindle.sh computer_science algorithm linux or [alias] computer_science algorithm linux will download pdfs of computer_science, algorithm and linux articles from wikipedia in your current directory and send a copy to your kindle in azw3 format.

Note: There's no max-limit on the number of articles you can input in the command. Just needs at least one.

Contribution

The script has only been tested on Ubuntu 22.04LTS so far (since that is the one I have).
If you'd like, you can contribute by adding instructions for other distros and even other operating systems! (Windows and Mac)

Additionally, You are also encouraged to add support for other e-readers.

About

A bash script to send wikipedia articles to kindle as azw3. Also downloads a pdf to your local directory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages