This commit is contained in:
parent
70dc17dd75
commit
2774b8e84a
63
README.md
63
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.
|
- Parses the email to extract the actual PDF download link.
|
||||||
- Downloads the PDF file and saves it to a local `data` directory.
|
- Downloads the PDF file and saves it to a local `data` directory.
|
||||||
- Runs as a daemon, checking for new emails periodically.
|
- Runs as a daemon, checking for new emails periodically.
|
||||||
|
- Hosts the downloaded PDF files on a local HTTP server with a styled listing.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Python 3.7+
|
- Python 3.7+
|
||||||
@ -49,45 +50,39 @@ This project is a Python daemon that connects to your Gmail account, searches fo
|
|||||||
|
|
||||||
## Usage
|
## 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
|
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)
|
|
||||||
|
|
||||||
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**:
|
|
||||||
```bash
|
```bash
|
||||||
sudo systemctl daemon-reload
|
python3 email_pdf_downloader.py
|
||||||
sudo systemctl enable email_reader.service
|
|
||||||
sudo systemctl start email_reader.service
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Check Status**:
|
The script will run in the background, checking for new emails every 5 minutes.
|
||||||
```bash
|
|
||||||
sudo systemctl status email_reader.service
|
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
|
## Configuration
|
||||||
- **SCOPES**: OAuth scopes for Gmail API access.
|
- **SCOPES**: OAuth scopes for Gmail API access.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user