Skip to content

inamcodes/flask_wheather_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌦️ Flask Weather App

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

Screenshot from 2026-06-30 17-38-43

Features

  • 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

Tech Stack

  • Backend: Python, Flask
  • Frontend: HTML, Jinja2 templates, Bootstrap 5
  • Weather Data: Weatherstack API
  • HTTP Requests: requests library

Project Structure

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)

Prerequisites

  • Python 3.8 or higher
  • A free or paid API key from Weatherstack

Setup & Installation

  1. Clone or extract the project

    cd wheather_app_api
  2. Create and activate a virtual environment (recommended)

    python -m venv venv
    source venv/bin/activate      # On Windows: venv\Scripts\activate
  3. Install dependencies

    The included requirements.txt contains 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
  4. 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
    
  5. Run the application

    python app.py

    The app will start in debug mode at:

    http://127.0.0.1:5000
    
  6. Open your browser and navigate to http://127.0.0.1:5000. Enter a city name and click Search to view the current weather.

How It Works

  1. The user submits a city name through the search form on index.html.
  2. app.py sends a GET request to the Weatherstack current endpoint with your API key and the city name as query parameters.
  3. The API responds with JSON data containing location and current weather details.
  4. If Weatherstack returns an error key (e.g., invalid city or API key), the app displays a friendly error message instead of crashing.
  5. On success, the weather data is passed to the Jinja2 template, which renders the temperature, conditions, humidity, wind speed, and UV index.

Environment Variables

Variable Description Required
API_KEY Your Weatherstack API access key Yes

⚠️ Never commit your real .env file or API key to version control. The .gitignore is already configured to exclude .env.

Notes on wheather.py

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

Known Limitations

  • The free tier of Weatherstack only supports HTTP (not HTTPS) requests, which is reflected in the BASE_URL used in app.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.

Possible Improvements

  • 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

License

This project is provided as-is for educational and personal use. Check Weatherstack's terms of service for API usage limits and licensing.

About

A simple, lightweight web application built with Flask that lets users look up the current weather for any city using the Weatherstack API.

Topics

Resources

Stars

Watchers

Forks

Contributors