This Python script automatizes the process of storing PDF files sent by a Kindle Scribe.
The whole script is based on Google's Gmail API, enabling it to parse email metadata and find the temporary link for the PDF.
When a
URLis then embedded in a link on the email sent to the user.
Once the URL has been found, the script fetches it via:
def fetch_pdf(pdf_link, filename):
# Download the PDF
import requests
response = requests.get(pdf_link)
with open(f"kindle_pdfs/{filename}.pdf", "wb") as pdf:
pdf.write(response.content)credentials.jsondownloadable after generating an ID client OAuth 2.0 via the Google API Dashboard.token.jsongenerated after loggin in via a link.
Before running the code it is essential to install the requirements.txt dependencies, it is recommended to use a python virtual environment:
python3 -m venv .venv
source .venv/bin/activateUse the appropriate
activateaccordingly (eg.activate.fishforfishshell)
pip3 install -r requirements.txtThe code is then runnable as following:
python3 main.pyThe PDFs will be saved in the kindle_pdfs/ folder.