A comprehensive Python application for analyzing the Belgian second-hand electric car market by scraping, processing, and visualizing data from multiple car listing websites.
- Project Description
- Features
- Prerequisites
- Installation & Setup
- Usage
- Project Structure
- Configuration
- Troubleshooting
- Development Setup
- Contributing
- License
- Contact/Support
The Electric Car Market Analyzer is designed to provide comprehensive insights into the Belgian electric vehicle market by collecting and analyzing data from major car listing platforms. This tool helps potential buyers, market researchers, and automotive enthusiasts make informed decisions by providing:
- Real-time market data from multiple sources
- Price trend analysis and drop detection
- Interactive visualizations for market exploration
- Data-driven insights into electric vehicle pricing and availability
- Car buyers looking for the best deals on electric vehicles
- Market researchers studying automotive trends
- Automotive dealers monitoring competitor pricing
- Data analysts interested in market dynamics
- Save time by aggregating data from multiple platforms
- Identify price drops and market opportunities
- Understand market trends through comprehensive analytics
- Make data-driven purchasing decisions
-
Multi-source web scraping from major Belgian car platforms:
- Gocar - Premium car listings platform
- AutoScout24 - European automotive marketplace
- 2ememain - Belgian classified ads platform
-
Advanced data processing:
- Data cleaning and normalization
- Electric vehicle identification and filtering
- Price range filtering (β¬500 - β¬300,000)
- Duplicate detection and removal
-
Price drop detection:
- Automatic comparison between scraping sessions
- Identification of vehicles with reduced prices
- Historical price tracking
-
Interactive web dashboard:
- Real-time data visualization using Plotly and Dash
- Price range filtering with interactive sliders
- Detailed vehicle information on hover
- Visit advertisement on click
- Refresh functionality for live updates
-
Comprehensive logging:
- Detailed operation logs for debugging
- Separate log files for each module
- Console and file output
-
Data export and visualization:
- Multiple chart types (box plots, scatter plots)
- SweetViz integration for automated data profiling
- Export capabilities for further analysis
- Python 3.9 or higher (as specified in pyproject.toml)
- UV package manager (recommended) or pip as fallback
- Operating System: Windows, macOS, or Linux
- Memory: Minimum 4GB RAM (8GB recommended for large datasets)
- Storage: At least 1GB free space for data and logs
- Gocar Bearer Token: Required for accessing Gocar API
- Browse to Gocar web site and get it from browser developer tools
- Token should be added to your
.envfile
- Stable internet connection for web scraping
- Access to target websites (some may have regional restrictions)
git clone https://github.com/Gauff/BelgianElectricCarMarketAnalyser.git
cd electricCarMarketAnalyserUV is a fast Python package manager that's 10-100x faster than pip:
# Install UV
pip install uvOr follow the official installation guide: https://github.com/astral-sh/uv
Using UV (recommended):
uv pip install -r src/requirements.txtUsing pip (fallback):
# Create virtual environment first
python -m venv venv
# Activate virtual environment
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r src/requirements.txtRequired packages include:
beautifulsoup4>=4.12.0- HTML parsing for web scrapingbotasaurus- Web automation frameworkdash>=2.14.0- Web application frameworkmatplotlib>=3.8.0- Plotting librarynumpy>=1.24.0- Numerical computingpandas>=2.1.0- Data manipulation and analysisplotly>=5.18.0- Interactive plottingrequests>=2.31.0- HTTP librarypython-dotenv>=1.0.0- Environment variable management
-
Copy the environment template:
cp src/.env.example src/.env
-
Edit the
.envfile and add your API credentials:GOCAR_BEARER_TOKEN=your_actual_token_here
-
Obtain Gocar Bearer Token:
- Visit the Gocar developer portal or contact their support
- Follow their authentication process
- Add the token to your
.envfile
Run the example script to test your setup:
python run_gocar_example.pyIf successful, you should see output similar to:
Current working directory: /path/to/electricCarMarketAnalyser
Running gocar script...
Successfully retrieved X cars from Gocar
Successfully loaded X cars from last file
Run the complete analysis pipeline:
python src/main.pyThis command will:
- Scrape data from all configured sources (Gocar, AutoScout24, 2ememain)
- Clean and process the data
- Detect price drops from previous runs
- Launch the interactive web dashboard
- Automatically open your browser to
http://127.0.0.1:8050/
Once the application is running, you can:
- View interactive scatter plots of car prices vs. registration years
- Filter by price range using the interactive slider
- Hover over data points to see detailed car information
- Click the "Refresh Data" button to update with latest scraped data
- Explore different car models and their price distributions
The application supports different execution modes:
Scrape data only (without launching dashboard):
from src.main import scrap_ads
scrap_ads()Launch dashboard with existing data:
from src.main import run_server
run_server()Scraped data is stored in:
results/- Processed datasets (pickle format)results/gocar/- Raw Gocar data (JSON)results/autoscout24/- Raw AutoScout24 data (JSON)results/2ememain/- Raw 2ememain data (JSON)
Logs are available in:
logs/- Application logs for debugging and monitoring
electricCarMarketAnalyser/
β
βββ src/ # Source code directory
β βββ sites/ # Website-specific scrapers
β β βββ autoscout24/ # AutoScout24 scraping module
β β βββ deuxieme_main/ # 2ememain scraping module
β β βββ gocar/ # Gocar API integration
β β βββ gocar.py # Main Gocar scraper
β β βββ gocar_data.py # Data models
β β βββ gocar_electric_car_search.json
β βββ data/ # Data models and utilities
β β βββ electric_car_data.py # ElectricCar class definition
β β βββ electric_car_models.py # Car model identification
β β βββ dataframes.py # DataFrame utilities
β βββ config.py # Configuration and paths
β βββ data_cleaning.py # Data cleaning utilities
β βββ data_preparation.py # Data processing pipeline
β βββ file_management.py # File I/O operations
β βββ graph_utils.py # Graph generation utilities
β βββ logging_config.py # Logging configuration
β βββ main.py # Main application entry point
β βββ requirements.txt # Python dependencies
β βββ utilities.py # General utility functions
β βββ visualization.py # Data visualization
β βββ .env.example # Environment variables template
β βββ .env # Environment variables (create this)
β
βββ results/ # Generated data files
β βββ autoscout24/ # AutoScout24 raw data
β βββ gocar/ # Gocar raw data
β βββ 2ememain/ # 2ememain raw data
β βββ YYYYMMDDHHMMSS_df.pkl # Processed datasets
β
βββ logs/ # Application logs
β βββ __main__.log # Main application logs
β βββ data_preparation.log # Data processing logs
β βββ autoscout24.log # AutoScout24 scraper logs
β βββ deuxieme_main.log # 2ememain scraper logs
β
βββ visualizations/ # Generated plots and charts
βββ screenshots/ # Application screenshots
βββ build/ # Build artifacts
βββ run_gocar_example.py # Example script for testing
βββ README.md # This file
βββ .gitignore # Git ignore rules
βββ .gitattributes # Git attributes
Core Modules:
main.py- Application entry point and Dash web serverdata_preparation.py- Data scraping and processing pipelineconfig.py- Centralized configuration management
Scraping Modules:
sites/gocar/- Gocar API integration with bearer token authenticationsites/autoscout24/- AutoScout24 web scrapingsites/deuxieme_main/- 2ememain classified ads scraping
Data Processing:
data_cleaning.py- Filters out non-electric vehicleselectric_car_models.py- Electric vehicle identificationdataframes.py- Price drop detection and analysis
Utilities:
file_management.py- File operations with timestamp managementlogging_config.py- Centralized logging setupvisualization.py- Chart generation and data visualization
The application uses environment variables for sensitive configuration. Create a .env file in the src/ directory:
# Gocar API Configuration
GOCAR_BEARER_TOKEN=your_gocar_bearer_token_hereThe src/config.py file manages paths and directories:
# Automatically created directories
RESULTS_DIR = 'results/' # Scraped data storage
VISUALIZATIONS_DIR = 'visualizations/' # Generated charts
LOGS_DIR = 'logs/' # Application logs
# Site-specific data directories
AUTOSCOUT24_RESULTS = 'results/autoscout24/'
DEUXIEMEMAIN_RESULTS = 'results/2ememain/'
GOCAR_RESULTS = 'results/gocar/'Price Filtering:
- Default range: β¬500 - β¬300,000
- Configurable in
data_preparation.py
Data Sources:
- All three sources are scraped in parallel for efficiency
- Individual sources can be disabled by modifying
data_preparation.py
Update Frequency:
- Manual execution by default
- Can be automated using cron jobs or task schedulers
Server Settings:
- Default port: 8050
- Debug mode: Enabled (disable for production)
- Auto-reload: Disabled to prevent conflicts
Display Options:
- Default price range: β¬2,000 - β¬20,000
- Interactive filtering available
- Real-time updates via refresh button
Error: ValueError: GOCAR_BEARER_TOKEN not found in environment variables
Solution:
- Ensure you have created the
.envfile in thesrc/directory - Verify the token is correctly added:
GOCAR_BEARER_TOKEN=your_token_here - Check that there are no extra spaces or quotes around the token
Error: ModuleNotFoundError: No module named 'dash'
Solution:
- Install dependencies using UV:
uv pip install -r src/requirements.txt - Or use pip with virtual environment:
pip install -r src/requirements.txt - Verify Python version compatibility (3.9+)
Error: Dashboard doesn't open or shows connection errors
Solution:
- Check if port 8050 is already in use
- Verify firewall settings allow local connections
- Try accessing manually:
http://127.0.0.1:8050/ - Check console logs for error messages
Error: Empty charts or "No data available" messages
Solution:
- Verify internet connection for web scraping
- Check if scraping sources are accessible
- Review logs in
logs/directory for scraping errors - Ensure Gocar token is valid and not expired
Error: PermissionError: [Errno 13] Permission denied
Solution:
- Ensure write permissions for
results/,logs/, andvisualizations/directories - Run with appropriate user permissions
- Check disk space availability
Enable detailed logging by modifying src/logging_config.py:
logger.setLevel(logging.DEBUG) # Change from INFO to DEBUGSlow scraping:
- Reduce the number of pages scraped per source
- Implement delays between requests to avoid rate limiting
- Check network connectivity and speed
High memory usage:
- Process data in smaller chunks
- Clear unused DataFrames after processing
- Monitor system resources during execution
Q: How often should I run the scraper? A: Daily runs are recommended for price drop detection. More frequent runs may trigger rate limiting.
Q: Can I add more car listing websites?
A: Yes, create a new module in src/sites/ following the existing patterns.
Q: How do I export data for external analysis?
A: Processed data is stored as pickle files in results/. Use pandas to load and export to CSV/Excel.
Q: Is the application suitable for production use? A: The current version is designed for research and personal use. For production, implement proper error handling, rate limiting, and monitoring.
This section covers the development environment setup for contributors and developers working on the Electric Car Market Analyzer project.
The project uses modern Python development tools for code quality, formatting, and type checking:
- Black - Code formatter for consistent styling
- Ruff - Fast Python linter and formatter (replaces flake8, isort, etc.)
- MyPy - Static type checker
- Pydantic v2 - Data validation library
- UV - Fast Python package manager
Using UV (recommended - 10-100x faster than pip):
uv pip install -r requirements-dev.txtOr using pip:
pip install -r requirements-dev.txtRun the unified development script to install everything automatically:
python development.py setupThis will:
- Install all development dependencies using UV (or pip as fallback)
- Validate that all tools are properly installed
- Create VS Code settings for optimal development experience
Use the consolidated development.py script for all development operations:
# Set up development environment
python development.py setup
# Format code with Black
python development.py format
# Lint code with Ruff
python development.py lint
# Type check with MyPy
python development.py type-check
# Auto-fix formatting and linting issues
python development.py fix
# Run all tools
python development.py allAll development tools are configured in pyproject.toml:
Black Configuration:
- Line length: 88 characters
- Target Python versions: 3.9+
- Excludes: logs, results, screenshots, visualizations
Ruff Configuration:
- Replaces: flake8, isort, pyupgrade, and more
- Enabled rules: pycodestyle, Pyflakes, isort, bugbear, comprehensions, pyupgrade, naming, security, simplify
- Import sorting with known first-party modules
MyPy Configuration:
- Target Python version: 3.9
- Lenient settings for gradual adoption
- Ignores missing imports for external libraries
The setup script automatically creates .vscode/settings.json with optimal settings:
- Black as the default formatter
- Format on save enabled
- Ruff linting enabled
- MyPy type checking enabled
- Automatic import organization
Before Committing:
# Run all tools to ensure code quality
python development.py allDuring Development:
# Auto-fix issues as you work
python development.py fixFor CI/CD Pipelines:
# Example GitHub Actions step
- name: Check code quality
run: |
uv pip install -r requirements-dev.txt
python development.py allUV Not Found:
# Install UV
pip install uv
# Or follow instructions at: https://github.com/astral-sh/uvTools Not Found:
- Use the
development.pyscript which uses UV to run tools - Or install tools globally:
pip install black ruff mypy
MyPy Module Errors:
- Run MyPy from the project root directory
- Ensure
src/is in your Python path - Use the provided scripts which handle paths correctly
The development tools help maintain high code quality:
Black: Automatically formats code for consistency Ruff: Provides import sorting, code style enforcement, bug detection, security checks, and performance suggestions MyPy: Catches type-related errors and provides better IDE integration
Key development-related files in the project:
electric-car-market-analyser/
βββ src/ # Main source code
β βββ data/ # Data models and processing
β βββ sites/ # Web scraping modules
β βββ requirements.txt # Production dependencies
βββ development.py # Unified development tools script
βββ requirements-dev.txt # Development dependencies
βββ pyproject.toml # Tool configuration (Python 3.9+)
βββ uv.lock # UV dependency lock file
βββ .vscode/settings.json # VS Code integration (auto-generated)
We welcome contributions to improve the Electric Car Market Analyzer! Here's how you can help:
- Fork the repository on GitHub
- Clone your fork:
git clone https://github.com/your-username/BelgianElectricCarMarketAnalyser.git cd electricCarMarketAnalyser - Create a development branch:
git checkout -b feature/your-feature-name
- Set up development environment:
# Install UV package manager (if not already installed) pip install uv # Install production dependencies uv pip install -r src/requirements.txt # Set up development tools python development.py setup
See the Development Setup section above for detailed information about development tools and workflow.
Code Quality:
- Run
python development.py allbefore committing to ensure code quality - Use
python development.py fixto auto-fix formatting and linting issues - Follow the automated code style enforced by Black and Ruff
- Add type hints where appropriate (checked by MyPy)
Development Workflow:
- Use the development tools provided:
python development.py setup - Format code automatically:
python development.py format - Check for issues:
python development.py lint - Ensure type safety:
python development.py type-check
Testing:
- Test your changes thoroughly
- Ensure existing functionality isn't broken
- Add unit tests for new features
- Run the full development tool suite before submitting
Documentation:
- Update README.md for new features
- Add inline comments for complex logic
- Update docstrings as needed
Bug Reports:
- Use GitHub Issues to report bugs
- Include error messages, logs, and steps to reproduce
- Specify your operating system and Python version
Feature Requests:
- Describe the proposed feature and its benefits
- Explain the use case and expected behavior
- Consider implementation complexity
Code Contributions:
- New scraping sources
- Data analysis features
- Visualization improvements
- Performance optimizations
- Bug fixes
- Ensure your code follows the style guidelines
- Update documentation as needed
- Test your changes thoroughly
- Create a pull request with:
- Clear description of changes
- Reference to related issues
- Screenshots for UI changes
This project is licensed under the MIT License - see the details below:
MIT License
Copyright (c) 2024 Electric Car Market Analyzer Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This project uses several open-source libraries, each with their own licenses:
- Dash - MIT License
- Plotly - MIT License
- Pandas - BSD 3-Clause License
- BeautifulSoup - MIT License
- Requests - Apache 2.0 License
GitHub Issues: Report bugs or request features
Documentation: This README contains comprehensive setup and usage instructions
Community: Check existing issues and discussions for similar problems
When seeking support:
-
Search existing issues first
-
Provide detailed information:
- Operating system and Python version
- Complete error messages
- Steps to reproduce the issue
- Relevant log files from
logs/directory
-
Include context:
- What you were trying to accomplish
- What you expected to happen
- What actually happened
This project is maintained by the community. Active contributors help review issues and pull requests.
This tool is for educational and research purposes. Users are responsible for:
- Complying with website terms of service
- Respecting rate limits and robots.txt files
- Using scraped data ethically and legally
- Obtaining necessary permissions for commercial use
Happy analyzing! πβ‘π
