|
A simple, lightweight web application built with Flask that lets users look up the current weather for any city using the Weatherstack API. The app features a clean, responsive UI styled with Bootstrap 5 |
|
- Search current weather conditions by city name
- Displays temperature, "feels like" temperature, humidity, wind speed, and UV index
- Shows a weather icon and a short description (e.g., "Partly cloudy")
- Displays local time and country for the searched location
- Graceful error handling for invalid cities or failed API requests
- Responsive, dark-themed UI built with Bootstrap 5
- Backend: Python, Flask
- Frontend: HTML, Jinja2 templates, Bootstrap 5
- Weather Data: Weatherstack API
- HTTP Requests:
requestslibrary
wheather_app_api/
├── app.py # Main Flask application and routes
├── wheather.py # Standalone script for testing the Weatherstack API
├── requirements.txt # Python dependencies
├── .env.example # Example environment variable file
├── .gitignore
└── templates/
└── index.html # Main page template (search form + results)
- Python 3.8 or higher
- A free or paid API key from Weatherstack
-
Clone or extract the project
cd wheather_app_api -
Create and activate a virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
The included
requirements.txtcontains many unrelated packages (TensorFlow, Streamlit, OpenCV, etc.) that aren't needed for this app. For a clean install, only the following are required:pip install Flask requests python-dotenv
Alternatively, to install everything listed in the original file:
pip install -r requirements.txt
-
Configure your API key
Copy the example environment file and add your Weatherstack API key:
cp .env.example .env
Then edit
.env:API_KEY=your_actual_weatherstack_api_key -
Run the application
python app.py
The app will start in debug mode at:
http://127.0.0.1:5000 -
Open your browser and navigate to
http://127.0.0.1:5000. Enter a city name and click Search to view the current weather.
- The user submits a city name through the search form on
index.html. app.pysends aGETrequest to the Weatherstackcurrentendpoint with your API key and the city name as query parameters.- The API responds with JSON data containing location and current weather details.
- If Weatherstack returns an
errorkey (e.g., invalid city or API key), the app displays a friendly error message instead of crashing. - On success, the weather data is passed to the Jinja2 template, which renders the temperature, conditions, humidity, wind speed, and UV index.
| Variable | Description | Required |
|---|---|---|
API_KEY |
Your Weatherstack API access key | Yes |
⚠️ Never commit your real.envfile or API key to version control. The.gitignoreis already configured to exclude.env.
wheather.py is a standalone test script (not used by the Flask app) that makes a direct request to the Weatherstack API for the city "Sukkur" and prints the raw JSON response. It's useful for quickly verifying that your API key works without running the full web app:
python wheather.py- The free tier of Weatherstack only supports
HTTP(notHTTPS) requests, which is reflected in theBASE_URLused inapp.py. - No caching is implemented, so each search triggers a fresh API call.
- The app currently supports only single-city lookups; there's no search history or favorites feature.
- Add unit conversion toggle (°C / °F)
- Add a 7-day or hourly forecast view
- Cache recent searches to reduce API calls
- Add geolocation-based weather lookup
- Migrate to HTTPS-supported weather API endpoint for production use
This project is provided as-is for educational and personal use. Check Weatherstack's terms of service for API usage limits and licensing.
