feature: DuckDuckGo weather widget extractor #25

Closed
opened 2026-02-14 16:12:32 +00:00 by Claude · 1 comment
Collaborator

Description

Mort's pkg/logic/weather2/weather2.go currently does ~300 lines of inline browser scraping to extract structured weather data from DuckDuckGo's weather widget. It opens https://duckduckgo.com/?q=weather+CITY, waits 3 seconds, then does complex text parsing and attribute extraction from div.react-module article elements.

This should be a proper site extractor in go-extractor's sites/duckduckgo package (or a new sites/duckduckgo/weather sub-package).

Proposed API

package duckduckgo // or duckduckgo/weather

type WeatherData struct {
    Location    string
    CurrentTemp float64
    Condition   string
    HighTemp    float64
    LowTemp     float64
    Humidity    string
    Wind        string
    Forecast    []DayForecast
    Hourly      []HourlyForecast
}

func (c Config) GetWeather(ctx context.Context, b extractor.Browser, city string) (*WeatherData, error)

Benefits

  • Mort's weather2.go would shrink from ~300 lines to ~20 lines
  • Other go-extractor consumers get weather data for free
  • Weather parsing logic is testable independently with mock HTML fixtures
  • Selector breakage is caught in go-extractor tests, not discovered in production mort

Reference

See mort/pkg/logic/weather2/weather2.go for the current implementation and ParseWeatherFromText() for the text parsing logic.

## Description Mort's `pkg/logic/weather2/weather2.go` currently does ~300 lines of inline browser scraping to extract structured weather data from DuckDuckGo's weather widget. It opens `https://duckduckgo.com/?q=weather+CITY`, waits 3 seconds, then does complex text parsing and attribute extraction from `div.react-module article` elements. This should be a proper site extractor in go-extractor's `sites/duckduckgo` package (or a new `sites/duckduckgo/weather` sub-package). ## Proposed API ```go package duckduckgo // or duckduckgo/weather type WeatherData struct { Location string CurrentTemp float64 Condition string HighTemp float64 LowTemp float64 Humidity string Wind string Forecast []DayForecast Hourly []HourlyForecast } func (c Config) GetWeather(ctx context.Context, b extractor.Browser, city string) (*WeatherData, error) ``` ## Benefits - Mort's weather2.go would shrink from ~300 lines to ~20 lines - Other go-extractor consumers get weather data for free - Weather parsing logic is testable independently with mock HTML fixtures - Selector breakage is caught in go-extractor tests, not discovered in production mort ## Reference See `mort/pkg/logic/weather2/weather2.go` for the current implementation and `ParseWeatherFromText()` for the text parsing logic.
Claude added the enhancementpriority/medium labels 2026-02-14 21:01:02 +00:00
Author
Collaborator

Implemented in PR #44. Added GetWeather() method with WeatherData and DayForecast types, extracting location, temperature, condition, high/low, humidity, wind, and multi-day forecast from DuckDuckGo's weather widget. Full mock-based test coverage included.

Implemented in PR #44. Added `GetWeather()` method with `WeatherData` and `DayForecast` types, extracting location, temperature, condition, high/low, humidity, wind, and multi-day forecast from DuckDuckGo's weather widget. Full mock-based test coverage included.
Sign in to join this conversation.