Skip to content

A website built with Flask and OpenWeather API that displays the weather forecast for any city. *Optimised for desktop and mobile view. NOTE: Website is down since Heroku removed free plans.

Notifications You must be signed in to change notification settings

kousen/python-weather-app

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Weather App

A modern Flask-based weather web application that provides comprehensive weather forecasts for any city worldwide. Built with a focus on user experience, security, and responsive design.

Note: This is an enhanced fork of the original project with additional features including temperature unit conversion, improved city selection, comprehensive testing, and performance optimizations.

✨ Features

Core Functionality

  • Real-time weather data for any city using OpenWeather API
  • 5-day weather forecast with detailed conditions
  • Multiple city disambiguation - when searching for cities like "Springfield", choose from available options
  • Smart duplicate removal - eliminates duplicate city entries from API responses

Enhanced User Experience

  • Temperature unit toggle - Switch between Celsius and Fahrenheit via page reload (ensures proper unit conversion for temperature AND wind speed: m/s ↔ mph)
  • Comprehensive weather details:
    • Current temperature with "feels like" temperature
    • Min/max temperatures for the day
    • Humidity percentage
    • Wind speed (properly converted based on unit preference)
    • Sunrise and sunset times
  • Loading indicators during API calls for better user feedback
  • Responsive design optimized for both desktop and mobile devices

Technical Improvements

  • Input sanitization to prevent security vulnerabilities
  • Robust error handling with graceful fallbacks
  • API timeout protection (5-second timeouts)
  • Comprehensive test suite with 11 integration tests
  • Rate limiting protection through optimized API usage

πŸ› οΈ Tech Stack

  • Backend: Flask 2.3.2 (Python web framework)
  • API: OpenWeather API (weather data and geocoding)
  • Frontend: HTML5, CSS3 (Grid & Flexbox), Vanilla JavaScript
  • Testing: pytest with mocking for API calls
  • Environment: python-dotenv for configuration
  • Deployment: Gunicorn-ready for production deployment

πŸ“‹ Setup Instructions

Prerequisites

Installation

  1. Clone the repository

    git clone <repository-url>
    cd python-weather-app
  2. Set up virtual environment

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

    pip install -r requirements.txt
  4. Configure environment variables

    # Create .env file or set environment variable
    export OPENWEATHERMAP_API_KEY=your_api_key_here
  5. Run the application

    python main.py
  6. Access the app

    • Open browser to http://localhost:5000

πŸ§ͺ Testing

Run the comprehensive test suite:

# Run all tests
pytest test_main.py -v

# Run specific test categories
pytest test_main.py::TestCityWeather -v        # Weather functionality
pytest test_main.py::TestErrorHandling -v      # Error handling
pytest test_main.py::TestHomePage -v           # Home page features

Test Coverage

  • βœ… Home page rendering and search functionality
  • βœ… Input sanitization and validation
  • βœ… Single city weather display
  • βœ… Multiple city selection workflow
  • βœ… Weather display by coordinates
  • βœ… Comprehensive error handling scenarios
  • βœ… API failure resilience

πŸ—οΈ Architecture

Security Features

  • Input sanitization - Removes potentially harmful characters
  • HTTPS API endpoints - Secure communication with OpenWeather
  • Environment variable storage - API keys never committed to code
  • Request timeouts - Prevents hanging on slow API responses
  • Error handling - Graceful degradation on failures

Performance Optimizations

  • Efficient API usage - Minimal requests to avoid rate limiting
  • Coordinate-based deduplication - Removes duplicate city entries
  • Responsive caching - Browser-level caching for static assets
  • Optimized CSS - Mobile-first design with media queries

πŸ“± User Interface

Pages

  1. Home Page - Clean search interface with loading indicators
  2. City Selection - When multiple cities match, users can choose the specific location
  3. Weather Display - Comprehensive weather information with unit toggle
  4. Error Page - User-friendly error messaging

Mobile Responsiveness

  • Adaptive layouts using CSS Grid and Flexbox
  • Touch-friendly buttons and controls
  • Optimized font sizes and spacing
  • Responsive images and icons

πŸ”„ Recent Improvements

Version 2.0 Updates

  • Smart city disambiguation - Handles cities with identical names
  • Enhanced weather details - Added humidity, feels-like temp, sunrise/sunset
  • Temperature unit toggle - Complete implementation using API unit parameters with proper wind speed conversion
  • Loading states - Visual feedback during API calls
  • Mobile optimization - Improved responsive design
  • Security hardening - Input validation and HTTPS enforcement
  • Test coverage - Comprehensive integration test suite

πŸš€ Deployment

Local Development

# Set up virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run the application
python main.py  # Runs on localhost:5000 with debug mode

Production Deployment

The app is configured for production deployment with Gunicorn:

gunicorn main:app

Environment variables required in production:

  • OPENWEATHERMAP_API_KEY - Your OpenWeather API key

πŸ›£οΈ Future Enhancements

  • Search history - Remember recent city searches
  • Favorite cities - Save frequently accessed locations
  • Weather alerts - Display severe weather warnings
  • Extended forecast - 7-day forecast option
  • Location detection - GPS-based weather for current location
  • Dark mode - Theme toggle for better accessibility

πŸ› Known Issues

  • iPad layout could be further optimized (spacing improvements needed)
  • Weather icons could have better fallbacks for unusual weather conditions

πŸ“Έ Screenshots

Desktop

Desktop Home Page

Desktop Weather Page

Desktop Error Page

Mobile

Mobile Weather Page Mobile Home Page

πŸ“š Resources & References

APIs & Documentation

Development Resources

Testing & Security

🎨 Design Credits

Images

Icons

All weather and UI icons provided by Icons8:

  • Weather condition icons (sun, rain, clouds, snow, etc.)
  • UI elements (search, navigation, thermometer)
  • Interactive buttons and indicators

πŸ‘¨β€πŸ’» Development

Built from scratch using modern web development practices:

  • Semantic HTML5 for accessibility
  • CSS Grid & Flexbox for responsive layouts
  • Progressive enhancement for JavaScript functionality
  • RESTful API integration with proper error handling
  • Test-driven development with comprehensive coverage

Original concept by Rachana Hegde β€’ Enhanced with modern features and best practices

About

A website built with Flask and OpenWeather API that displays the weather forecast for any city. *Optimised for desktop and mobile view. NOTE: Website is down since Heroku removed free plans.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 48.4%
  • HTML 28.6%
  • CSS 22.9%
  • Procfile 0.1%