A Flask-based weather application that fetches current weather and forecast data from OpenWeatherMap API, stores search history in MySQL, and provides a web UI for search, history viewing, filtering, editing, deleting, and exporting data.
- Search weather by city name, ZIP/postal code, GPS coordinates, or landmarks
- Auto-complete and location suggestions
- Current weather + 5-day forecast + hourly temperature chart
- Store search results history in MySQL database
- View search history with pagination, date range, and location filtering
- Edit and delete historical records directly in the web interface
- Export history data to CSV format
- Display related YouTube videos for searched locations
- Backend: Python, Flask
- Frontend: HTML, CSS, JavaScript, Chart.js
- Database: MySQL (using PyMySQL driver)
- APIs: OpenWeatherMap, YouTube Data API v3
- Python 3.7+
- MySQL Server
- OpenWeatherMap API key
- Google YouTube API key
git clone https://github.com/yourusername/weather-app.git
cd weather-appCREATE DATABASE weather_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE weather_app;
CREATE TABLE weather_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
location VARCHAR(255),
latitude DOUBLE,
longitude DOUBLE,
temperature FLOAT,
humidity INT,
wind_speed FLOAT,
description VARCHAR(255),
icon VARCHAR(50),
recorded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);pip install -r requirements.txtEdit config.py
WEATHER_API_KEY = 'your_openweathermap_api_key'
YOUTUBE_API_KEY = 'your_youtube_api_key'python app.pyApp will be available at http://127.0.0.1:5000
-
Use the search box on the main page to find weather for any location.
-
Click "View History" to see your past searches.
-
Filter history by location and date range.
-
Edit temperature, humidity, or location fields directly in the table.
-
Delete unwanted records with the delete button.
-
Export filtered records as a CSV file.
├── app.py # Flask backend routes and logic
├── db.py # Database connection and CRUD functions
├── weather_api.py # OpenWeatherMap API wrappers
├── config.py # API keys and config
├── requirements.txt # Python dependencies
├── templates/
│ ├── index.html # Main page template
│ └── history.html # History page template
└── static/
└── script.js # Frontend JavaScript logic
-
Ensure your MySQL user has permissions to create and modify tables.
-
API rate limits apply for OpenWeatherMap and YouTube APIs.
-
For production deployment, configure environment variables and use a production-ready WSGI server.