A data analysis and visualization system that combines Spotify audio features with weather data to create interactive insights through a beautiful dashboard.
- π΅ Spotify Integration: Fetch audio features for tracks using Spotify Web API
- π€οΈ Weather Data: Retrieve weather information from OpenWeatherMap API
- π Data Analysis: Perform correlation analysis between music and weather patterns
- π Interactive Dashboard: Beautiful Plotly Dash interface with real-time filtering
- π³ Docker Support: Containerized deployment for easy setup
- π§ͺ Comprehensive Testing: Property-based testing with Hypothesis
- π Structured Logging: JSON logging with configurable levels
- β‘ Caching: Smart caching for improved performance
- Python 3.9+
- Docker (optional)
- Spotify Developer Account
- OpenWeatherMap API Account
git clone https://github.com/your-username/spotify-weather-mashup.git
cd spotify-weather-mashupCopy the example environment file and configure your API keys:
cp .env.example .envEdit .env with your API credentials:
# Spotify API Configuration
SPOTIFY_CLIENT_ID=your_spotify_client_id_here
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret_here
# OpenWeatherMap API Configuration
OPENWEATHER_API_KEY=your_openweather_api_key_here
# Application Configuration
DEFAULT_CITY=London
DASHBOARD_PORT=8050
DEBUG_MODE=false# Build and run with Docker Compose
docker-compose up --build
# Or use the build script
./scripts/docker-build.sh
./scripts/docker-run.sh# Install dependencies
pip install -r requirements.txt
# Run the application
python -m src.mainOpen your browser and navigate to:
- Local: http://localhost:8050
- Docker: http://localhost:8050
Run the application interactively to fetch real data:
python -m src.mainYou'll be prompted to enter:
- City name for weather data
- Search query for Spotify tracks
Run in demo mode without API calls:
python -m src.main --demo# Start the application
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the application
docker-compose downThe application follows a layered architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Presentation Layer β
β (Plotly Dash Dashboard) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Business Logic Layer β
β (Data Analysis & Processing) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data Access Layer β
β (Spotify API & Weather API Clients) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Infrastructure Layer β
β (Configuration & Logging) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- SpotifyClient: Handles Spotify Web API authentication and data fetching
- WeatherClient: Manages OpenWeatherMap API integration
- DataProcessor: Cleans and validates data from both APIs
- DataAnalyzer: Performs statistical analysis and correlation computation
- DashboardApp: Creates interactive visualizations with Plotly Dash
- Correlation Heatmap: Shows relationships between audio features and weather metrics
- Scatter Plots: Interactive plots with customizable axes
- Time Series Charts: Trends over time for both music and weather data
- Summary Statistics: Key metrics and statistical summaries
- Real-time Filtering: Filter data by date range, city, and features
- Hover Tooltips: Detailed information on data points
- Export Functionality: Download data in JSON or CSV format
- Responsive Design: Works on desktop and mobile devices
The project includes comprehensive testing with both unit tests and property-based tests.
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test types
pytest -m unit # Unit tests only
pytest -m property # Property-based tests only
pytest -m integration # Integration tests onlytests/
βββ unit/ # Unit tests
βββ integration/ # Integration tests
βββ property/ # Property-based tests
βββ fixtures/ # Test data and fixtures
βββ conftest.py # Test configuration
| Variable | Description | Default | Required |
|---|---|---|---|
SPOTIFY_CLIENT_ID |
Spotify API client ID | - | β |
SPOTIFY_CLIENT_SECRET |
Spotify API client secret | - | β |
OPENWEATHER_API_KEY |
OpenWeatherMap API key | - | β |
DEFAULT_CITY |
Default city for weather data | London | β |
DASHBOARD_PORT |
Dashboard server port | 8050 | β |
DASHBOARD_HOST |
Dashboard server host | 0.0.0.0 | β |
DEBUG_MODE |
Enable debug mode | false | β |
LOG_LEVEL |
Logging level | INFO | β |
LOG_FORMAT |
Log format (json/console) | json | β |
MAX_TRACKS |
Maximum tracks to fetch | 50 | β |
WEATHER_DAYS |
Days of weather data | 7 | β |
CACHE_DURATION_HOURS |
Cache duration in hours | 1 | β |
- Go to Spotify Developer Dashboard
- Create a new app
- Copy the Client ID and Client Secret
- Add them to your
.envfile
- Sign up at OpenWeatherMap
- Get your free API key
- Add it to your
.envfile
Data processing completed:
- Spotify tracks: 45
- Weather records: 7
- Correlations found: 12
- Insights: 3
Key Insights:
1. Strong positive correlation between energy and temperature (r=0.67)
2. Danceability shows slight upward trend over time
3. Weather conditions significantly impact musical preferences
Note: Add actual screenshots of your dashboard here
# Build production image
docker build -t spotify-weather-mashup:prod .
# Run with production settings
docker run -d \
--name spotify-weather-mashup \
-p 80:8050 \
--env-file .env \
--restart unless-stopped \
spotify-weather-mashup:prod# Start with reverse proxy
docker-compose --profile production up -dThis includes:
- Application container
- Nginx reverse proxy
- SSL termination (configure certificates)
- Rate limiting
- Health checks
# Check your API keys
python -c "
from src.config.manager import ConfigManager
config = ConfigManager().get_config()
print('Spotify ID:', config.spotify.client_id[:10] + '...')
print('Weather Key:', config.weather.api_key[:10] + '...')
"# Find process using port 8050
lsof -i :8050
# Kill the process
kill -9 <PID># Clean up Docker resources
docker system prune -a
# Rebuild without cache
docker-compose build --no-cacheThe application includes a health check endpoint:
# Check application health
curl http://localhost:8050/_dash-dependencies
# Or use the built-in health check
python -c "
from src.main import SpotifyWeatherMashup
app = SpotifyWeatherMashup()
print(app.health_check())
"- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit install
# Run tests before committing
pytestThis project is licensed under the MIT License - see the LICENSE file for details.
- Spotify Web API for music data
- OpenWeatherMap API for weather data
- Plotly Dash for the interactive dashboard
- Hypothesis for property-based testing
If you have any questions or issues:
- Check the troubleshooting section
- Search existing issues
- Create a new issue
Made with β€οΈ by Your Name# SpotifyTracksVsWeather