Checks your Gmail Inbox for Mails send from Kindle downloads pdf and stores it
Go to file
2024-12-03 12:41:27 +01:00
.gitignore fixed web layout 2024-11-08 21:57:01 +01:00
.htaccess for security 2024-11-08 22:17:58 +01:00
amznMailConverter.service made it simpler and to be run within a webserver on scrapy 2024-11-08 21:25:14 +01:00
daemon.py fixed header 2024-11-08 22:20:27 +01:00
Dockerfile made it simpler and to be run within a webserver on scrapy 2024-11-08 21:25:14 +01:00
email_pdf_downloader.py do not replace dashes as it will continuously download files 2024-12-03 12:41:27 +01:00
LICENSE Initial commit 2024-11-08 09:26:26 +01:00
pdf_server.py fixed header 2024-11-08 22:20:27 +01:00
README.md 2024-11-08 19:02:43 +01:00
requirements.txt made it simpler and to be run within a webserver on scrapy 2024-11-08 21:25:14 +01:00
web.service code improvements 2024-11-08 18:54:36 +01:00
webSimple.py open in browser 2024-11-13 16:44:32 +01:00

Amazon Kindle Email PDF Downloader

This project is a Python daemon that connects to your Gmail account, searches for unread emails from "Amazon Kindle Support" containing PDF download links, and automatically downloads the PDFs to a specified local directory if they dont already exist. The script runs as a background service and checks for new emails at a specified interval.

Features

  • Automatically reads unread emails from Gmail.
  • Searches for emails from "Amazon Kindle Support" with PDF download links.
  • Parses the email to extract the actual PDF download link.
  • Downloads the PDF file and saves it to a local data directory.
  • Runs as a daemon, checking for new emails periodically.
  • Hosts the downloaded PDF files on a local HTTP server with a styled listing.

Requirements

  • Python 3.7+
  • Google API credentials for Gmail API access
  • Gmail API access enabled in Google Cloud Console

Installation

  1. Clone the Repository:

    git clone https://github.com/yourusername/amznMailConverter.git
    cd amznMailConverter
    
  2. Install Dependencies:

    pip install -r requirements.txt
    

    The requirements.txt should include:

    google-auth
    google-auth-oauthlib
    google-auth-httplib2
    google-api-python-client
    requests
    beautifulsoup4
    python-daemon  # Only if using the daemon library
    
  3. Set Up Google API Credentials:

    • Create a project in the Google Cloud Console.
    • Enable the Gmail API.
    • Download the OAuth 2.0 Client Credentials JSON file, rename it to credentials.json, and place it in the project root directory.
  4. Authorize Access:

    • On first run, the script will prompt you to authorize Gmail API access. Follow the instructions in the browser to grant permissions.
    • After authorization, a token.json file will be generated to store your access token.

Usage

Daemon Script

To run the email-checking script as a daemon, use one of the following methods:

  1. Using Python Daemon Library (Recommended for Simplicity):

    python3 email_pdf_downloader.py
    

    The script will run in the background, checking for new emails every 5 minutes.

  2. Using Systemd (Linux):

    • Create a Systemd Service file /etc/systemd/system/email_reader.service with appropriate configurations.
    • Enable and start the service.

PDF Server

This project includes a local HTTP server for hosting downloaded PDF files. It runs on port 8000 by default and lists all PDF files in the data directory in a styled HTML format.

  • Start the Server:
    python3 pdf_server.py
    

PDF Server Code Explanation

The PDFServer class is a custom HTTP server that serves PDF files from a specified directory. It includes a custom HTML-styled listing for an enhanced user experience.

  • Class Initialization: Sets the directory and port for serving files.
  • PDFRequestHandler: A custom request handler that filters and displays only PDF files with a dark-themed, material-styled HTML format.
    • list_directory: Overrides the directory listing method to filter only PDF files and style the output.
    • generate_html: Generates HTML content, listing available PDF files with a custom dark theme.
    • send_html_response: Sends the styled HTML response to the client.

Configuration

  • SCOPES: OAuth scopes for Gmail API access.
  • SEARCH_QUERY: Query to filter emails by sender ("Amazon Kindle Support").
  • SCRIPT_DIR: Base directory where files are saved.
  • Interval: The script is set to check for new emails every 5 minutes (300 seconds). You can adjust this interval in the run_daemon function in email_pdf_downloader.py.

Logging

Logging information (success messages, errors) is printed to the console or saved to systemd logs when running as a systemd service.

License

This project is licensed under the MIT License.