feature: add hourly forecast, precipitation, and icon hints to weather extractor #52

Merged
steve merged 1 commits from feature/weather-hourly-precip-icons into main 2026-02-15 21:23:35 +00:00
Collaborator

Summary

Adds missing fields to the DuckDuckGo weather extractor as described in #51:

  • Hourly forecast: New HourlyForecast struct with Time, Temp, Condition, Precipitation, and IconHint fields. Extracted via .module__hourly-item elements.
  • Precipitation percentage: Added Precipitation int field to both DayForecast and HourlyForecast. Uses -1 sentinel for "unavailable" (matches mort's convention).
  • Icon hints: Added IconHint string field to both structs. Reads icon type from element aria-label, title, or alt attributes (in priority order), providing reliable weather categorization (e.g., "PartlyCloudy", "Snow", "MostlyCloudy").

Struct changes

type WeatherData struct {
    // ... existing fields ...
    Hourly []HourlyForecast // NEW
}

type DayForecast struct {
    // ... existing fields ...
    Precipitation int    // NEW: 0-100, -1 if unavailable
    IconHint      string // NEW: from element attributes
}

type HourlyForecast struct { // NEW
    Time          string
    Temp          float64
    Condition     string
    Precipitation int    // 0-100, -1 if unavailable
    IconHint      string // from element attributes
}

New helper

extractIconHint(nodes) reads icon type from aria-label > title > alt attribute priority chain, matching the same approach used in mort's weather2 module.

Test plan

  • TestExtractWeather - updated with hourly items, precipitation, and icon hints
  • TestGetWeather_MockBrowser - verifies hourly data flows through full path
  • TestExtractWeather_Empty - verifies zero hourly data on empty doc
  • TestExtractWeather_NoPrecipitation - verifies -1 sentinel when no precip element
  • TestExtractIconHint_Priority - verifies aria-label > title > alt fallback chain
  • Full test suite passes (go test ./...)

Closes #51

## Summary Adds missing fields to the DuckDuckGo weather extractor as described in #51: - **Hourly forecast**: New `HourlyForecast` struct with `Time`, `Temp`, `Condition`, `Precipitation`, and `IconHint` fields. Extracted via `.module__hourly-item` elements. - **Precipitation percentage**: Added `Precipitation int` field to both `DayForecast` and `HourlyForecast`. Uses -1 sentinel for "unavailable" (matches mort's convention). - **Icon hints**: Added `IconHint string` field to both structs. Reads icon type from element `aria-label`, `title`, or `alt` attributes (in priority order), providing reliable weather categorization (e.g., "PartlyCloudy", "Snow", "MostlyCloudy"). ### Struct changes ```go type WeatherData struct { // ... existing fields ... Hourly []HourlyForecast // NEW } type DayForecast struct { // ... existing fields ... Precipitation int // NEW: 0-100, -1 if unavailable IconHint string // NEW: from element attributes } type HourlyForecast struct { // NEW Time string Temp float64 Condition string Precipitation int // 0-100, -1 if unavailable IconHint string // from element attributes } ``` ### New helper `extractIconHint(nodes)` reads icon type from aria-label > title > alt attribute priority chain, matching the same approach used in mort's `weather2` module. ## Test plan - [x] `TestExtractWeather` - updated with hourly items, precipitation, and icon hints - [x] `TestGetWeather_MockBrowser` - verifies hourly data flows through full path - [x] `TestExtractWeather_Empty` - verifies zero hourly data on empty doc - [x] `TestExtractWeather_NoPrecipitation` - verifies -1 sentinel when no precip element - [x] `TestExtractIconHint_Priority` - verifies aria-label > title > alt fallback chain - [x] Full test suite passes (`go test ./...`) Closes #51
Claude added 1 commit 2026-02-15 21:22:27 +00:00
feature: add hourly forecast, precipitation, and icon hints to weather extractor
All checks were successful
CI / build (pull_request) Successful in 30s
CI / vet (pull_request) Successful in 46s
CI / test (pull_request) Successful in 49s
469171da9c
Add HourlyForecast struct and Hourly field to WeatherData for hourly
temperature/condition data. Add Precipitation (int, -1 if unavailable)
and IconHint (from aria-label/title/alt attributes) to both DayForecast
and HourlyForecast. This enables downstream consumers like mort to
replace inline DuckDuckGo scraping with a single GetWeather() call.

Closes #51

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
steve merged commit cff4713282 into main 2026-02-15 21:23:35 +00:00
steve deleted branch feature/weather-hourly-precip-icons 2026-02-15 21:23:35 +00:00
Sign in to join this conversation.