Skip to content

A modern, feature-rich **cross-platform** PowerShell script that displays a 7-day weather forecast with automatic location detection and multi-language support.

License

Notifications You must be signed in to change notification settings

sorcerer86pt/powershell-weather-forecast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

PowerShell Weather Forecast

Release License Platform PowerShell

A modern, feature-rich cross-platform PowerShell script that displays a 7-day weather forecast with automatic location detection and multi-language support.

Features

  • โœ… Cross-Platform - Works on Windows, Linux, and macOS
  • โœ… Smart Location Detection - Automatically detects OS and uses the appropriate location service
    • Windows: Windows Location Service
    • Linux: GeoClue2
    • macOS: CoreLocation (via whereami)
    • All: IP-based geolocation fallback
  • โœ… Multi-Language Support - Extensible locale system with 7 languages included
  • โœ… Comprehensive Weather Data - Temperature, precipitation, wind speed, and weather conditions
  • โœ… Multiple Temperature Units - Celsius or Fahrenheit
  • โœ… Beautiful Console UI - Clean, formatted output with weather emojis
  • โœ… Free APIs - Uses Open-Meteo (no API key required) and OpenStreetMap Nominatim
  • โœ… Rate Limiting - Respects API usage policies automatically
  • โœ… Fallback Support - Built-in English descriptions if locale files are missing

Requirements

All Platforms

  • PowerShell 7+ (recommended) or PowerShell 5.1+ (Windows only)
  • Internet connection

Platform-Specific (Optional, for automatic location detection)

Windows:

  • Windows 10/11 with Location Services enabled

Linux:

  • GeoClue2 installed and running
  • Install: sudo apt install geoclue-2.0 (Debian/Ubuntu) or sudo dnf install geoclue2 (Fedora)

macOS:

  • whereami utility (optional but recommended)
  • Install: brew install whereami

Installation

Windows

  1. Install PowerShell (if not already installed):

    • Windows 10/11 comes with PowerShell 5.1
    • For PowerShell 7+: Download from GitHub
  2. Clone or download the repository:

git clone https://github.com/yourusername/powershell-weather-forecast.git
cd powershell-weather-forecast
  1. Enable Location Services (optional):

    • Go to Settings โ†’ Privacy โ†’ Location
    • Turn on "Location for this device"
  2. Run the script:

.\WeatherForecast.ps1

Linux

  1. Install PowerShell:

    Debian/Ubuntu:

    # Install prerequisites
    sudo apt-get update
    sudo apt-get install -y wget apt-transport-https software-properties-common
    
    # Download and install PowerShell
    wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    sudo apt-get update
    sudo apt-get install -y powershell

    Fedora:

    # Add Microsoft repository
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/fedora/$(rpm -E %fedora)/prod.repo
    
    # Install PowerShell
    sudo dnf install -y powershell

    Arch Linux:

    yay -S powershell-bin
    # or
    paru -S powershell-bin
  2. Install GeoClue2 (optional, for location detection):

    Debian/Ubuntu:

    sudo apt install geoclue-2.0

    Fedora:

    sudo dnf install geoclue2

    Arch Linux:

    sudo pacman -S geoclue
  3. Clone or download the repository:

git clone https://github.com/yourusername/powershell-weather-forecast.git
cd powershell-weather-forecast
  1. Make the script executable (optional):
chmod +x WeatherForecast.ps1
  1. Run the script:
pwsh ./WeatherForecast.ps1

macOS

  1. Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install PowerShell:
brew install powershell/tap/powershell
  1. Install whereami (optional, for location detection):
brew install whereami
  1. Clone or download the repository:
git clone https://github.com/yourusername/powershell-weather-forecast.git
cd powershell-weather-forecast
  1. Run the script:
pwsh ./WeatherForecast.ps1

Quick Start (Any Platform)

If you just want to try it without location services:

# Skip system location and use IP-based detection
pwsh ./WeatherForecast.ps1 -SkipSystemLocation

# Or specify a city directly
pwsh ./WeatherForecast.ps1 -City "London"

Usage

Basic Usage

# Auto-detect location and show forecast
.\WeatherForecast.ps1

Advanced Usage

# Specific city
.\WeatherForecast.ps1 -City "Tokyo"

# Use Fahrenheit
.\WeatherForecast.ps1 -Units Fahrenheit

# Force specific language
.\WeatherForecast.ps1 -LocaleOverride "pt"

# Skip system location (go directly to IP lookup)
.\WeatherForecast.ps1 -SkipSystemLocation

# Combine parameters
.\WeatherForecast.ps1 -City "New York" -Units Fahrenheit -LocaleOverride "es"

Parameters

Parameter Type Description Default
-City String Specify city name directly None (auto-detect)
-Units String Temperature units: Celsius or Fahrenheit Celsius
-SkipSystemLocation Switch Skip Windows Location Service, use IP instead False
-LocaleOverride String Force specific language (e.g., en, pt, fr) System language

Supported Languages

  • ๐Ÿ‡ฌ๐Ÿ‡ง English (en)
  • ๐Ÿ‡ต๐Ÿ‡น Portuguese (pt)
  • ๐Ÿ‡ซ๐Ÿ‡ท French (fr)
  • ๐Ÿ‡ช๐Ÿ‡ธ Spanish (es)
  • ๐Ÿ‡ฉ๐Ÿ‡ช German (de)
  • ๐Ÿ‡ฎ๐Ÿ‡น Italian (it)
  • ๐Ÿ‡ฏ๐Ÿ‡ต Japanese (ja)
  • ๐Ÿ‡บ๐Ÿ‡ฆ Ukrainian (uk)

Want to add more? See locales/README.md

Location Detection Strategy

The script automatically detects your OS and uses a tiered approach to find your location:

Windows

  1. Windows Location Service - Most accurate, requires permission
  2. IP Geolocation - Fallback using ip-api.com (city-level accuracy)
  3. Manual Entry - Prompts for city name if automatic methods fail

Linux

  1. GeoClue2 - Uses the Linux standard geolocation service
  2. IP Geolocation - Fallback using ip-api.com (city-level accuracy)
  3. Manual Entry - Prompts for city name if automatic methods fail

macOS

  1. CoreLocation via whereami - Uses macOS location services
  2. IP Geolocation - Fallback using ip-api.com (city-level accuracy)
  3. Manual Entry - Prompts for city name if automatic methods fail

APIs Used

Example Output

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘     Weather Forecast - 7 Day Outlook              โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โœ“ Location: Porto, Portugal

Fetching 7-day weather forecast for Porto...

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  7-Day Weather Forecast for Porto, Portugal                              โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Date         Icon Weather      High  Low  Rain           Wind   
----         ---- -------      ----  ---  ----           ----   
Mon 27/10    โ˜€๏ธ   Clear        22ยฐC  15ยฐC -              12 km/h
Tue 28/10    ๐ŸŒค๏ธ   M.Clear      21ยฐC  14ยฐC -              15 km/h
Wed 29/10    โ›…   P.Cloudy     19ยฐC  13ยฐC 2.5mm (60%)    18 km/h
Thu 30/10    โ˜”   Rain         17ยฐC  12ยฐC 8.2mm (85%)    22 km/h

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Weather data: Open-Meteo API | Location: OpenStreetMap Nominatim
Language: English (en)
Last updated: 2025-10-27 14:23:45

Contributing

Contributions are welcome! This project uses automatic semantic versioning based on Conventional Commits.

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/amazing-feature)
  3. Make your changes
  4. Commit using conventional commit format (see below)
  5. Push to your fork and create a Pull Request

Commit Message Format

Use conventional commits for automatic versioning:

  • feat: - New feature (bumps minor version: 1.0.0 โ†’ 1.1.0)
  • fix: - Bug fix (bumps patch version: 1.0.0 โ†’ 1.0.1)
  • docs: - Documentation changes
  • perf: - Performance improvements
  • refactor: - Code refactoring
  • BREAKING CHANGE: - Breaking changes (bumps major version: 1.0.0 โ†’ 2.0.0)

Examples:

feat: add support for hourly forecasts
fix: resolve location detection on WSL
docs: update installation instructions
feat!: redesign command line parameters

BREAKING CHANGE: Parameter names have changed

See CONTRIBUTING.md for detailed guidelines.

Ways to Contribute

  • ๐ŸŒ Adding new language translations (see locales/README.md)
  • ๐Ÿ› Reporting bugs or suggesting features
  • ๐Ÿ“š Improving the code or documentation
  • โœ… Adding tests and improving cross-platform support

License

This project is open source and available under the MIT License.

Credits

Troubleshooting

Location service not working

Windows:

  • Ensure Windows Location Services are enabled: Settings โ†’ Privacy โ†’ Location
  • Try using -SkipSystemLocation to use IP-based location instead

Linux:

  • Ensure GeoClue2 is installed: sudo apt install geoclue-2.0 or sudo dnf install geoclue2
  • Check if GeoClue2 service is running: systemctl status geoclue
  • Try using -SkipSystemLocation to use IP-based location instead

macOS:

  • Install whereami: brew install whereami
  • Grant location permissions when prompted
  • Try using -SkipSystemLocation to use IP-based location instead

Locale not loading

  • Check that locale files exist in the locales/ subdirectory
  • Verify JSON files are valid and UTF-8 encoded
  • Script falls back to built-in English if locale files are missing

API rate limits

  • The script automatically rate-limits Nominatim requests (1/second)
  • If you encounter issues, wait a few minutes before trying again

PowerShell version

Version History

See CHANGELOG.md for detailed version history.

This project follows Semantic Versioning:

  • Major version (X.0.0): Breaking changes
  • Minor version (0.X.0): New features, backwards compatible
  • Patch version (0.0.X): Bug fixes and improvements

About

A modern, feature-rich **cross-platform** PowerShell script that displays a 7-day weather forecast with automatic location detection and multi-language support.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •