A weather dashboard app I built using Flask and JavaScript that shows current weather and forecasts for cities around the world.
- Shows real-time weather for any city in the world
- Automatically detects your location for local weather
- 5-day forecast with hourly details
- Search for cities with smart autocomplete
- Save your favorite cities for quick access
- Keeps track of your recent searches
- Shows UV index information
- Cool animated backgrounds that change with the weather
- Works great on both desktop and mobile
- Fast loading thanks to smart caching
- Good error handling so it won't crash on you
- Flask - The main Python web framework I used
- Flask-Caching - For making things load faster
- Requests - To get data from weather APIs
- Gunicorn - Production web server
- JavaScript - Plain vanilla JS, no fancy frameworks
- HTML5 - Modern HTML structure
- CSS3 - Styling with animations
- Font Awesome - Nice looking icons
- OpenWeatherMap API - Where I get all the weather data
- OpenWeatherMap Geocoding API - For location stuff
weather-dashboard/
├── app.py # Main Flask application
├── config.py # Configuration settings
├── models.py # In-memory data structures
├── services.py # Business logic and API services
├── utils.py # Utility functions
├── requirements.txt # Python dependencies
├── Dockerfile # Container configuration
├── fly.toml # Fly.io deployment config
├── templates/
│ └── index.html # Main HTML template
└── static/
├── styles.css # Main stylesheet
└── js/
├── main.js # Application initialization
├── weather-api.js # API communication
├── weather-display.js # Weather data presentation
├── city-search.js # Search functionality
├── location-service.js # Geolocation services
├── favorites.js # Favorites management
├── ui-utils.js # UI utilities
└── weather-translations.js # Weather condition translations
- Python 3.8 or newer
- An API key from OpenWeatherMap (it's free - just sign up at openweathermap.org)
-
Get the code
git clone <repository-url> cd weather-dashboard
-
Set up a virtual environment (this keeps things clean)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required packages
pip install -r requirements.txt
-
Create your environment file Make a
.envfile in the main folder and add:API_KEY=your_openweathermap_api_key_here SECRET_KEY=your_secret_key_here FLASK_CONFIG=development LOG_LEVEL=INFO
-
Start it up
python app.py
Open your browser and go to
http://localhost:5000
-
Build it
docker build -t weather-dashboard . -
Run it
docker run -p 8080:8080 -e API_KEY=your_api_key weather-dashboard
I set up three different modes:
- Development (
development) - Has debug mode on and lots of logging - Testing (
testing) - For running tests - Production (
production) - Optimized for when it's live
You can switch between them using the FLASK_CONFIG environment variable.
GET /weather- Get current weather by city nameGET /weather_by_coords- Get weather using GPS coordinatesGET /forecast- Get 5-day forecast
GET /city_suggestions- Get city suggestions when typingGET /reverse_geocode- Turn coordinates into city names
GET/POST/DELETE /favorites- Handle favorite citiesGET /analytics- See what cities people search for mostGET /popular_cities- Get the most popular cities
GET /health- Check if everything is workingPOST /clear_cache- Clear the cache when needed
I tried to keep everything organized and easy to understand:
- app.py - Main Flask app with all the routes
- services.py - The business logic and API calls to OpenWeatherMap
- models.py - Simple in-memory storage for caching and stats
- utils.py - Helper functions for validation and formatting
- config.py - Different settings for dev/test/production
The JavaScript is split into modules so it's not one giant mess:
- Modular Design - Each feature has its own file
- Event-Driven - Different parts talk to each other through events
- Mobile Friendly - Works on phones and tablets too
- Works Everywhere - Falls back gracefully on older browsers
- User types something or clicks a button
- JavaScript handles the input and validates it
- Makes a request to my Flask backend
- Backend checks the cache first, then calls OpenWeatherMap if needed
- Data gets cached for next time
- Sends the weather data back to the frontend
- JavaScript updates what the user sees
- Smart Caching - Weather data gets saved so I don't have to ask the API every time
- Request Throttling - Limits how often city suggestions are fetched to avoid spamming the API
- Browser Caching - Search suggestions get saved in your browser
- Background Loading - Some stuff loads in the background so it feels faster
- Optimized Files - CSS and JS files are compressed and versioned
- Input Validation - Everything users type gets checked and cleaned
- Rate Limiting - Prevents people from abusing the API
- Good Error Handling - Errors don't crash the app or leak info
- HTTPS - Encrypted connections in production
- XSS Protection - Prevents malicious scripts from running
Works on:
- Chrome 70 and newer
- Firefox 65 and newer
- Safari 12 and newer
- Edge 79 and newer
Feel free to help make this better! Here's how:
- Fork this repo
- Create a new branch (
git checkout -b cool-new-feature) - Make your changes and commit them (
git commit -m 'Added something cool') - Push to your branch (
git push origin cool-new-feature) - Open a Pull Request
This project uses the MIT License. Check the LICENSE file for the boring legal stuff.
- Weather data comes from OpenWeatherMap
- Icons are from Font Awesome
- Hosted on Fly.io