Skip to main content

A grabber for weather.com data with various output formats.

Project description

Weather Forecast CLI Script

Overview

This script fetches and parses weather forecast data from Weather.com and formats it for display in various environments such as a terminal or Waybar, a status bar tool. It leverages pyquery for HTML parsing and provides detailed weather information, including hourly and daily predictions, formatted for ease of use.

Waybar widget

Weather widget on Waybar

Terminal Console

Weather widget on terminal console

Features

  • Retrieves current weather and forecasts for a specified location.
  • Displays weather data in different formats:
    • Console output: Richly formatted weather data with icons.
    • Waybar JSON: For integration with Waybar.
  • Supports multiple languages for Weather.com data.
  • Includes data such as:
    • Current temperature and "feels-like" temperature.
    • Wind speed, humidity, visibility, and air quality.
    • Hourly and daily forecasts with icons and precipitation chances.

Requirements

Requires Python 3 or newer.

Install the package and all dependencies with:

pip install .

Or, for development (editable install with dev dependencies):

pip install -e .[dev]

Output Formats

Console Output

The script displays a formatted weather summary, including:

  • Current weather status.
  • Temperature (current, max/min).
  • Wind, humidity, visibility, and air quality.
  • Hourly and daily forecasts with icons.

Waybar JSON

The JSON includes:

  • text: Current weather icon and temperature.
  • alt: Weather status.
  • tooltip: Detailed weather information.
  • class: Status code for further customization.

JSON General output

Here the following JSON Schema for this output.

The key values for this json is:

  • temperature: An object containing the temperature information with the following fields:
    • current: The current temperature.
    • feel: The temperature feel
    • max : The maximum temperature
    • min : The minimum temperature

There's also other fields like hourly_predictions and daily_predictions containing lists of predictions informations. More defaults on JSON Schema.

Integration with Waybar

To integrate the script with Waybar:

  1. Add a custom script module in Waybar's configuration:

    {
        "modules-left": ["custom/weather"],
        "custom/weather": {
            "exec": "weathergrabber --output waybar",
            "interval": 600
        }
    }
    
  2. Reload Waybar to apply the changes.

Error Handling

  • Validates weather_id and lang inputs.
  • Handles HTTP errors gracefully, including 404 errors for invalid locations.

CI & Test Coverage

Test Status codecov

The test suite is run automatically on every push and pull request using GitHub Actions. Coverage results are uploaded to Codecov and displayed above.

To run tests and check coverage locally:

pytest --cov=weathergrabber --cov-report=term

License

This script is open-source and available under the MIT License.

CLI Usage

You can run the CLI as an installed command:

weathergrabber [location_name] [options]

Or as a Python module:

python -m weathergrabber [location_name] [options]

Importing as a Python module

You can also use the main API or CLI entry point in your own Python code:

import weathergrabber

# Call the main API
weathergrabber.main(log_level="INFO", location_name="London", location_id="", lang="en-GB", output="console", keep_open=False, icons="emoji")

# Or run the CLI programmatically
weathergrabber.main_cli()

Arguments

  • location_name (positional, optional): City name, zip code, etc. If not provided, you can use --location-id or the WEATHER_LOCATION_ID environment variable.

Options

  • --location-id, -l : 64-character-hex code for location (from Weather.com)
  • --lang, -L : Language (e.g., pt-BR, fr-FR). Defaults to system locale if not set.
  • --output, -o : Output format. One of console, json, or waybar. Default: console.
  • --keep-open, -k : Keep open and refresh every 5 minutes (only makes sense for console output).
  • --icons, -i : Icon set. fa for Font-Awesome, emoji for emoji icons. Default: emoji.
  • --log : Set logging level. One of debug, info, warning, error, critical. Default: critical.

Environment Variables

  • LANG : Used as default language if --lang is not set.
  • WEATHER_LOCATION_ID : Used as default location if neither location_name nor --location-id is set.

Example Usage

weathergrabber "London" --output console --lang en-GB
weathergrabber --location-id 1234567890abcdef... --output json
weathergrabber "Paris" -o waybar -i fa

Or as a Python module:

python -m weathergrabber "London" --output console --lang en-GB
python -m weathergrabber --location-id 1234567890abcdef... --output json
python -m weathergrabber "Paris" -o waybar -i fa

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weathergrabber-0.0.8b3.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weathergrabber-0.0.8b3-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file weathergrabber-0.0.8b3.tar.gz.

File metadata

  • Download URL: weathergrabber-0.0.8b3.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for weathergrabber-0.0.8b3.tar.gz
Algorithm Hash digest
SHA256 0d0c10a35cc5dd97e28533e6c1410ac642d8c47a621cbdac8c1de6b0ec7ee02e
MD5 a8b2f0fa43f082abce84bcd190afeb45
BLAKE2b-256 fee2333b2f147f6801363755f8405037f7821361c98e137714c17a410e3778c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathergrabber-0.0.8b3.tar.gz:

Publisher: publish-to-pypi.yml on cjuniorfox/weathergrabber

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weathergrabber-0.0.8b3-py3-none-any.whl.

File metadata

File hashes

Hashes for weathergrabber-0.0.8b3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ec9d9b9a38544c1f7e0e6409b532607aca1c3c19b031cb1f654fdb335ea320d
MD5 2cbc3f0d35ab786b913185e45f4dc526
BLAKE2b-256 b56bbe1b5c40d4c368f2c434f7ca171bdfa4557de93f1908fab4d734501a3493

See more details on using hashes here.

Provenance

The following attestation bundles were made for weathergrabber-0.0.8b3-py3-none-any.whl:

Publisher: publish-to-pypi.yml on cjuniorfox/weathergrabber

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page