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
packageduckduckgo// or duckduckgo/stockstypeStockDatastruct{SymbolstringPricefloat64Changefloat64ChangePctfloat64Highfloat64Lowfloat64Openfloat64Volumestring}typeStockPeriodstringconst(Period1DStockPeriod="1D"Period5DStockPeriod="5D"Period1MStockPeriod="1M"PeriodYTDStockPeriod="YTD"Period1YStockPeriod="1Y"Period5YStockPeriod="5Y"PeriodAllStockPeriod="All")// GetStockQuote extracts structured stock datafunc(cConfig)GetStockQuote(ctxcontext.Context,bextractor.Browser,symbolstring)(*StockData,error)// GetStockChart screenshots the stock chart widget for a given periodfunc(cConfig)GetStockChart(ctxcontext.Context,bextractor.Browser,symbolstring,periodStockPeriod)([]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.
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.
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
Mort's
pkg/logic/stock.godoes inline browser scraping to get stock prices from DuckDuckGo. It openshttps://duckduckgo.com/?q=stock+SYMBOL, waits 5 seconds, findsdiv.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/duckduckgopackage.Proposed API
Benefits
Reference
See
mort/pkg/logic/stock.gofor the current implementation.Implemented in PR #44. Added
GetStockQuote()returningStockData(symbol, name, price, change, change%) andGetStockChart()for screenshotting the chart widget with period selection (1D–All). Full mock-based test coverage included.