This project contains a bot that processes and digests newsletter content, focusing on specific topics of interest.
- Python 3.x
- pip (Python package installer)
- Docker (optional, for containerized deployment)
- PostgreSQL
-
Clone this repository or download the source code.
-
Navigate to the project directory:
cd /path/to/newsletter-digest
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up the configuration:
- Create a
.env
file based on the.env.sample
file and add the necessary environment variables, including theGEMINI_API_KEY
and database connection details. - Review and modify the
config.yaml
file to set up email settings, search criteria, and other configurations.
- Create a
The config.yaml
file contains important settings:
- Email settings (allowed senders and domains)
- Search settings (criteria, minimum relevance score)
- Output settings
- Cron job settings
Ensure these are correctly set up for your use case.
This project uses PostgreSQL to store processed articles. Follow these steps to set up the database:
- Install PostgreSQL on your system if you haven't already.
- Create a new database for the project.
- Update the
.env
file with your PostgreSQL connection details:Replace the values with your specific PostgreSQL configuration.DB_NAME=your_database_name DB_USER=your_username DB_PASSWORD=your_password DB_HOST=localhost DB_PORT=5432
This project uses Alembic for database migrations. The alembic/env.py
file is configured to use the database connection details from your .env
file.
To check for pending migrations and apply them if necessary, use the db_migrate.py
script:
python db_migrate.py
This script will:
- Check the current database revision
- Check for any pending migrations
- Apply migrations if needed
It's recommended to run this script as part of your deployment process to ensure the database schema is always up to date.
For more advanced usage, you can use Alembic commands directly:
-
To generate a new migration after making changes to your models:
alembic revision --autogenerate -m "Description of the changes"
-
To apply all pending migrations:
alembic upgrade head
For more information on using Alembic, refer to the Alembic documentation.
To run the newsletter digest bot locally, use the following command:
python discord_bot.py
To run the bot using Docker:
-
Build the Docker image:
docker build -t newsletter-digest-bot .
-
Run the Docker container:
docker run -p 5000:5000 -p 80:80 newsletter-digest-bot
The application includes a health check endpoint at /healthz
. You can access it at:
http://localhost:5000/healthz
This endpoint returns a JSON response {"message": "ok"}
with a status code of 200 when the application is running correctly.
discord_bot.py
: Main entry point for the botconfig_manager.py
: Manages configuration loading and validationemail_crawler.py
: Handles email retrieval (to be implemented)email_parser.py
: Parses email content and processes articlesalembic.ini
: Configuration file for Alembic database migrationsalembic/
: Directory containing database migration scriptsenv.py
: Alembic environment configuration, handles database connection
db_migrate.py
: Script for checking and applying database migrations
- Email parsing and content extraction
- Integration with Google's Gemini AI for content summarization
- Discord bot for displaying paginated article results
- Health check endpoint for monitoring application status
- Database storage and migration support using SQLAlchemy and Alembic
- Automated database migration script for deployment
The bot generates logs in the newsletter_bot.log
file. Check this file for execution details and any issues.
If you encounter any issues:
- Ensure all dependencies are correctly installed.
- Verify that the
.env
file is properly configured with all required variables. - Check the
newsletter_bot.log
file for any error messages or warnings. - If using Docker, ensure the container is running and ports are correctly mapped.
- Use the health check endpoint to verify the application's status.
- For database-related issues, check your PostgreSQL connection details in the
.env
file. - Run
python db_migrate.py
to check and apply any pending database migrations.
For further assistance, please contact the project maintainer.