This repository contains a Docker Compose configuration for running the NetNews application, which consists of two components:
- NetNewsCore: Fetches RSS feeds, summarizes articles using OpenAI's API, and stores the summaries in a SQLite database.
- NetNewsWeb: A web interface for viewing the summarized news articles.
- Docker and Docker Compose installed on your Synology NAS
- An OpenAI API key
- Synology DS423+ NAS (or compatible model)
The project is organized as follows:
-
core/: Contains the NetNewsCore componentmain.py: Main script for fetching and summarizing RSS feedsDockerfile: Container configuration for NetNewsCorerequirements.txt: Python dependencies for NetNewsCore
-
web/: Contains the NetNewsWeb componentapp.py: Flask web application for displaying news summariesDockerfile: Container configuration for NetNewsWebrequirements.txt: Python dependencies for NetNewsWebtemplates/: HTML templates for the web interfacethe_news.html: Template for displaying news summaries
images/: Static images used in the web interface
-
compose.yaml: Docker Compose configuration for running both components -
RSSFeeds.ini: Configuration file for RSS feeds -
.env: Environment variables configuration (API keys, settings) -
example.env: Example environment variables file -
README.md: This documentation file
-
Clone this repository to your Synology NAS or copy the files to a directory on your NAS.
-
Create the required directory for persistent data:
mkdir -p /volume1/docker/netnews
-
Copy the RSSFeeds.ini file to the persistent data directory:
cp RSSFeeds.ini /volume1/docker/netnews/
-
Configure your OpenAI API key:
Option 1: Edit the .env file in the NetNewsCore directory:
nano .env
Replace
your_openai_api_keywith your actual OpenAI API key.Option 2: Provide the API key directly when starting the containers (see next step).
-
Build and start the containers:
OPENAI_API_KEY=your_openai_api_key docker-compose up -d
Replace
your_openai_api_keywith your actual OpenAI API key. This will override any key set in the .env file. -
The NetNewsCore container will run once and stop, while the NetNewsWeb container will continue running.
-
Access the web interface by navigating to
http://your-nas-ip:8081in your web browser.
To run NetNewsCore at 5am daily to gather new data:
- Open the Task Scheduler in your Synology DSM.
- Create a new scheduled task.
- Run as
rootor a user with sufficient permissions to run Docker commands. - Select "User-defined script" as the task type.
- Set the schedule to run at 5am daily.
- In the "Run command" field, enter:
cd /volume1/docker/netnews /usr/local/bin/docker-compose run --rm netnewscore
To add or remove RSS feeds:
-
Edit the RSSFeeds.ini file in the persistent data directory:
nano /volume1/docker/netnews/RSSFeeds.ini
-
Add or remove feeds in the format:
Feed Name = Feed URL, Number of Articles to Summarize -
Save the file.
-
The changes will take effect the next time NetNewsCore runs.
The following environment variables can be set in the .env file or passed directly to the container:
OPENAI_API_KEY: Your OpenAI API keyAI_MODEL: The OpenAI model to use (default: gpt-3.5-turbo)
FEED_TIMEOUT: Timeout in seconds for RSS feed requests (default: 30)MAX_RETRIES: Maximum number of retry attempts for API calls (default: 3)
RETENTION_DAYS: Number of days to keep entries in the database (default: 30)
LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) (default: INFO)LOG_FILE: Path to log file (default: netnews.log)
NetNewsCore now supports command-line arguments for more flexible configuration:
docker-compose run netnewscore python /app/main.py [OPTIONS]Available options:
--config PATH: Path to RSS feeds configuration file--db PATH: Path to SQLite database file--env PATH: Path to .env file
--workers N: Number of parallel workers (ignored, sequential processing is used)--timeout N: Timeout for RSS feed requests in seconds--retention N: Number of days to keep entries--model MODEL: OpenAI model to use--max-retries N: Maximum number of API call retries
--log-level LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)--log-file PATH: Path to log file
--feeds FEED [FEED ...]: Specific feeds to process (by name)
Example to process only specific feeds with increased timeout:
docker-compose run netnewscore python /app/main.py --feeds "NYT World News" "CBC Technology & Science" --timeout 60The Docker Compose configuration includes a bridge network that allows the containers to access the internet. This is necessary for:
- Fetching RSS feeds from external sources
- Communicating with the OpenAI API for generating summaries
The bridge network is configured automatically when you start the containers with Docker Compose.
The NetNewsCore component has been enhanced with several new features and improvements:
- Sequential Processing: Process RSS feeds one at a time for improved reliability with SQLite
- Database Indexing: Improved database performance with indexes on frequently queried fields
- Configurable Timeouts: Adjust timeouts to handle slow RSS feeds
- Retry Mechanism: Automatically retry failed API calls with exponential backoff
- Improved Error Handling: Better handling of network issues, API errors, and malformed feeds
- Data Validation: Validate feed entries before processing to prevent errors
- Data Retention Policy: Automatically clean up old entries to manage database size
- Feed Selection: Process only specific feeds when needed
- Comprehensive Logging: Detailed logs with configurable log levels
- Command-Line Interface: Flexible configuration through command-line arguments
- Environment Variable Configuration: Easy configuration through environment variables
- Code Organization: Better structured code for easier maintenance
- Documentation: Comprehensive documentation of features and configuration options
When working with this application, please follow these security best practices:
-
API Key Management:
- Never commit your actual OpenAI API key to version control
- Use environment variables or the
.envfile to store your API key - Consider using Docker secrets or a secure vault for production deployments
- Regularly rotate your API keys as a security measure
-
Access Control:
- Restrict access to the web interface using network controls or a reverse proxy with authentication
- Limit access to the Docker host to authorized users only
- Use strong passwords for all accounts with access to the system
-
Data Protection:
- The application stores summarized content in a SQLite database
- Ensure the database file has appropriate file permissions
- Consider encrypting sensitive data if required by your organization's policies
If you encounter issues:
- Make sure the
/volume1/docker/netnewsdirectory exists and is writable. - Check that your OpenAI API key is valid.
- Verify that your NAS can access the internet to fetch RSS feeds and communicate with the OpenAI API.
- Ensure that your Synology NAS firewall settings allow outbound connections to the internet.
- Check the logs of the containers:
docker-compose logs netnewscore docker-compose logs netnewsweb
- Review the log file specified in the LOG_FILE environment variable for detailed error information.
- If you're having network connectivity issues, try restarting the Docker service on your Synology NAS.
Contributions to NetNews are welcome! Here's how you can contribute:
-
Report Issues: If you find a bug or have a suggestion for improvement, please open an issue on the repository.
-
Submit Pull Requests: If you'd like to contribute code:
- Fork the repository
- Create a new branch for your feature or bugfix
- Make your changes
- Submit a pull request with a clear description of the changes
-
Documentation: Improvements to documentation are always appreciated.
-
Testing: Help test the application in different environments and report any issues.
Please ensure your code follows the existing style and includes appropriate documentation and tests.