This service automates processing unread Gmail messages with PDF attachments from a specified sender, extracts structured event details using an LLM, uploads the PDF to Google Drive, and creates Google Calendar events that include a shareable file link. It can be run either as a long-lived service that polls Gmail on a schedule or as a one-time execution for manual processing.
- Queries Gmail for unread messages from a configured sender that include PDF attachments.
- Uploads the PDF attachments to Google Drive (optionally into a specific folder) and shares a view link.
- Extracts text from PDFs and sends it to an OpenAI model for structured parsing.
- Creates Calendar events populated with the parsed data plus a link to the uploaded PDF.
- Supports both continuous operation and one-time execution modes.
- Python 3.10+
- Google OAuth credentials with Gmail modify, Calendar, and Drive (file upload) scopes saved to
token.json(overridable withGOOGLE_TOKEN_PATH). - Environment variables:
SENDER_EMAIL: Email address to filter unread messages.OPENAI_API_KEY: Key for the OpenAI API.OPENAI_MODEL(optional): Model name to use (defaults togpt-4o-mini).POLL_INTERVAL_SECONDS(optional): How often the service checks for new messages in continuous mode (defaults to 300 seconds).DRIVE_FOLDER_ID(optional): Google Drive folder ID where PDFs should be uploaded.
-
Install dependencies:
pip install -r requirement.txt
-
Copy
.env_exampleto.envand fill in your values:cp .env_example .env # edit .env with your sender email and OpenAI key -
Run the service:
Run the service as a long-running process that polls Gmail periodically:
python main.py
or explicitly:
python main.py --mode continuous
Process current unread messages once and exit:
python main.py --mode once
--mode {once,continuous} Run mode: 'once' for single execution or 'continuous' for continuous operation (default: continuous) --sender SENDER Email address to filter messages from (default: from SENDER_EMAIL env variable) --interval INTERVAL Interval between checks in seconds for continuous mode (default: from POLL_INTERVAL_SECONDS env variable or 300)Note: Environment variables are loaded from the
.envfile using python-dotenv. You can also override them on the command line if needed:SENDER_EMAIL=organizer@example.com OPENAI_API_KEY=... POLL_INTERVAL_SECONDS=300 python main.py
The service will print the ID of each created Calendar event. Processed messages are marked as read to avoid duplication.