A Python-based tool that tracks and displays product prices from Systembolaget (the Swedish alcohol retail monopoly). The tool fetches product data, stores it in a SQLite database, and generates a web interface to display the information.
- Robust API Integration: Fetches product data from Systembolaget's API with retry logic and error handling
- Price Tracking: Tracks price changes over time with comprehensive history
- APK Calculation: Calculates APK (Alcohol Per Krona) for value comparison
- Modern Web Interface: Responsive design with advanced filtering and sorting
- Statistics Dashboard: Real-time statistics and analytics
- CLI Interface: Command-line tools for database management and queries
- Data Validation: Comprehensive data validation and error handling
- Performance Optimized: Database indexing and batch processing for large datasets
- Python 3.11 or higher
- Required Python packages (see
requirements.txt
):- requests
- beautifulsoup4
- bs4
- python-dateutil (optional)
- Clone the repository:
git clone https://github.com/yourusername/systemet.git
cd systemet
- Install the required packages:
pip install -r requirements.txt
The application now includes a comprehensive CLI for easy management:
# Update the product database
python cli.py update
# Generate the web interface
python cli.py generate
# Show database statistics
python cli.py stats
# Search for products
python cli.py search "vodka"
# Get product details
python cli.py product 12345
# Perform full update (database + web interface)
python cli.py full-update
To update the product database with the latest information:
python main.py
This will:
- Fetch the latest product data from Systembolaget
- Update the SQLite database with retry logic
- Track price changes with comprehensive logging
- Calculate price change percentages
- Handle errors gracefully
To generate the static website:
python deploy.py
This will:
- Read data from the database
- Generate a modern, responsive HTML file (
index.html
) - Include statistics dashboard
- Provide advanced filtering and export options
Open index.html
in your web browser to see:
- Statistics Dashboard: Overview of total products, average prices, and price changes
- Advanced Table: Sortable, searchable table with all products
- Price Tracking: Color-coded price changes (red for increases, green for decreases)
- APK Analysis: Value comparison with visual indicators
- Export Options: Copy, CSV, Excel, and print functionality
- Responsive Design: Works on desktop and mobile devices
The application supports environment variable configuration:
# API Configuration
export SYSTEMET_API_KEY="your_api_key"
export SYSTEMET_API_URL="https://api-extern.systembolaget.se/sb-api-ecommerce/v1/productsearch/search"
# Database Configuration
export SYSTEMET_DB_NAME="products.db"
# Request Configuration
export SYSTEMET_MAX_RETRIES="3"
export SYSTEMET_RETRY_DELAY="2"
export SYSTEMET_TIMEOUT="30"
# Web Interface Configuration
export SYSTEMET_WEB_TITLE="Systemet Price Tracker"
export SYSTEMET_PAGE_LENGTH="25"
Stores current product information including:
- Basic product details (name, number, producer, etc.)
- Current price and price change percentage
- Alcohol content and volume
- APK value for value comparison
- Category and country information
Tracks all price changes with:
- Product ID
- Price at the time
- Timestamp of the change
- Comprehensive logging with file and console output
- Retry logic for API requests with exponential backoff
- Graceful error handling for database operations
- Data validation for all incoming product data
- Database indexing for faster queries
- Batch processing for large datasets
- Connection pooling and optimized SQLite settings
- Efficient memory usage with streaming processing
- Type hints throughout the codebase
- Comprehensive documentation
- Modular design with separation of concerns
- Configuration management with environment variable support
- Modern, responsive design with CSS Grid and Flexbox
- Statistics dashboard with real-time data
- Advanced filtering and search capabilities
- Export functionality (CSV, Excel, Print)
- Mobile-friendly interface
- Visual indicators for APK values and price changes
systemet/
├── main.py # Main data fetching and processing
├── deploy.py # Web interface generation
├── cli.py # Command-line interface
├── config.py # Configuration management
├── utils.py # Utility functions
├── url_parser.py # URL parsing utilities
├── requirements.txt # Python dependencies
├── products.db # SQLite database
└── index.html # Generated web interface
- Add configuration options to
config.py
- Implement core functionality in appropriate modules
- Add CLI commands to
cli.py
if needed - Update web interface in
deploy.py
if UI changes are required - Add tests and update documentation
Feel free to submit issues and enhancement requests!
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) license. This means you are free to:
- Share — copy and redistribute the material in any medium or format
- Adapt — remix, transform, and build upon the material for any purpose, even commercially
Under the following terms:
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
See the LICENSE file for full details.