This script automates the downloading, parsing, and forwarding of SpotOn subscription reports received via Gmail. The script is designed to save ink and paper by eliminating the printing of the email body and only printing the PDF attachments.
SpotOn subscriptions are sent to Gmail accounts, which receive daily reports. The sites use HP ePrint to print these reports directly. However, this method forces the printing of the email body, which includes a large SpotOn image, consuming a lot of ink and paper.
This script downloads the attachments, extracts the PDF files, and forwards them to the printer without the email body. The script is hosted and scheduled to run every morning on the server at Northside. Each site has its own printer address, intermediary email account, and script.
- Deletes old files from the previous day to prevent reprinting
- Downloads all unread report files from the reporting email inbox
- Forwards PDF attachments to the printer without the email body
- Clone the repository:
git clone https://https://github.com/BLibs/Pit-N-Pub_Auto_Reports.git
- Navigate to the project directory:
cd Pit-N-Pub_Auto_Reports
- Install the required dependencies:
pip install -r requirements.txt
Create a config.py
file in the project directory and define the following variables:
PATH = 'path_to_save_files'
HOST = 'your_imap_host'
EMAIL = 'your_email'
PASSWORD = 'your_email_password'
RECIPIENT_EMAIL = 'printer_email_address'
SMTP_SERVER = 'your_smtp_server'
SMTP_PORT = your_smtp_port
The script can either be ran directly as a Python file or compiled into an .exe with Pyinstaller
- Run the script to start the automation process:
python main.py
- Compile the .exe which can then be ran in any environment, in my case as a scheduled task in Windows.
pyinstaller --onefile --clean main.py