feature: DuckDuckGo stock widget extractor #26

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

Description

Mort's pkg/logic/stock.go does inline browser scraping to get stock prices from DuckDuckGo. It opens https://duckduckgo.com/?q=stock+SYMBOL, waits 5 seconds, finds div.module__content, clicks time period selectors, waits another 5 seconds, then screenshots the widget.

This should be a proper site extractor in go-extractor's sites/duckduckgo package.

Proposed API

package duckduckgo // or duckduckgo/stocks

type StockData struct {
    Symbol    string
    Price     float64
    Change    float64
    ChangePct float64
    High      float64
    Low       float64
    Open      float64
    Volume    string
}

type StockPeriod string
const (
    Period1D  StockPeriod = "1D"
    Period5D  StockPeriod = "5D"
    Period1M  StockPeriod = "1M"
    PeriodYTD StockPeriod = "YTD"
    Period1Y  StockPeriod = "1Y"
    Period5Y  StockPeriod = "5Y"
    PeriodAll StockPeriod = "All"
)

// GetStockQuote extracts structured stock data
func (c Config) GetStockQuote(ctx context.Context, b extractor.Browser, symbol string) (*StockData, error)

// GetStockChart screenshots the stock chart widget for a given period
func (c Config) GetStockChart(ctx context.Context, b extractor.Browser, symbol string, period StockPeriod) ([]byte, error)

Benefits

  • Eliminates hardcoded 5-second sleeps in mort (can use WaitForNetworkIdle or selector waits)
  • Extracts structured data instead of just screenshots
  • Chart screenshot function still available for the visual approach
  • Time period navigation handled cleanly

Reference

See mort/pkg/logic/stock.go for the current implementation.

## Description Mort's `pkg/logic/stock.go` does inline browser scraping to get stock prices from DuckDuckGo. It opens `https://duckduckgo.com/?q=stock+SYMBOL`, waits 5 seconds, finds `div.module__content`, clicks time period selectors, waits another 5 seconds, then screenshots the widget. This should be a proper site extractor in go-extractor's `sites/duckduckgo` package. ## Proposed API ```go package duckduckgo // or duckduckgo/stocks type StockData struct { Symbol string Price float64 Change float64 ChangePct float64 High float64 Low float64 Open float64 Volume string } type StockPeriod string const ( Period1D StockPeriod = "1D" Period5D StockPeriod = "5D" Period1M StockPeriod = "1M" PeriodYTD StockPeriod = "YTD" Period1Y StockPeriod = "1Y" Period5Y StockPeriod = "5Y" PeriodAll StockPeriod = "All" ) // GetStockQuote extracts structured stock data func (c Config) GetStockQuote(ctx context.Context, b extractor.Browser, symbol string) (*StockData, error) // GetStockChart screenshots the stock chart widget for a given period func (c Config) GetStockChart(ctx context.Context, b extractor.Browser, symbol string, period StockPeriod) ([]byte, error) ``` ## Benefits - Eliminates hardcoded 5-second sleeps in mort (can use WaitForNetworkIdle or selector waits) - Extracts structured data instead of just screenshots - Chart screenshot function still available for the visual approach - Time period navigation handled cleanly ## Reference See `mort/pkg/logic/stock.go` for the current implementation.
Claude added the enhancementpriority/medium labels 2026-02-14 21:01:03 +00:00
Author
Collaborator

Implemented in PR #44. Added GetStockQuote() returning StockData (symbol, name, price, change, change%) and GetStockChart() for screenshotting the chart widget with period selection (1DAll). Full mock-based test coverage included.

Implemented in PR #44. Added `GetStockQuote()` returning `StockData` (symbol, name, price, change, change%) and `GetStockChart()` for screenshotting the chart widget with period selection (`1D`–`All`). Full mock-based test coverage included.
Sign in to join this conversation.