From 2774b8e84aca17689f38716ef0a86228817a1146 Mon Sep 17 00:00:00 2001 From: maru21 Date: Fri, 8 Nov 2024 19:02:43 +0100 Subject: [PATCH] --- README.md | 63 +++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index aad316a..165ab69 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This project is a Python daemon that connects to your Gmail account, searches fo - 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+ @@ -49,45 +50,39 @@ This project is a Python daemon that connects to your Gmail account, searches fo ## Usage -To run the script as a daemon, use one of the following methods: +### Daemon Script -### 1. Using Python Daemon Library (Recommended for Simplicity) +To run the email-checking script as a daemon, use one of the following methods: -```bash -python3 email_pdf_downloader.py -``` - -The script will run in the background, checking for new emails every 5 minutes. - -### 2. Using Systemd (Linux) - -1. **Create a Systemd Service**: - - Create a file `/etc/systemd/system/email_reader.service`: - ```ini - [Unit] - Description=Email PDF Downloader Daemon - - [Service] - ExecStart=/usr/bin/python3 /path/to/email_pdf_downloader.py - Restart=always - User=your_username - WorkingDirectory=/path/to/project - - [Install] - WantedBy=multi-user.target - ``` - -2. **Enable and Start the Service**: +1. **Using Python Daemon Library (Recommended for Simplicity)**: ```bash - sudo systemctl daemon-reload - sudo systemctl enable email_reader.service - sudo systemctl start email_reader.service + python3 email_pdf_downloader.py ``` -3. **Check Status**: - ```bash - sudo systemctl status email_reader.service - ``` + 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**: + ```python + 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.