refactor: deduplicate numericOnly and DuckDuckGo result extraction
- Extract identical numericOnly inline functions from powerball and megamillions into shared sites/internal/parse.NumericOnly with tests - Extract duplicated DuckDuckGo result parsing from Search() and GetResults() into shared extractResults() helper Closes #13, #14 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/go-extractor"
|
||||
"gitea.stevedudenhoeffer.com/steve/go-extractor/sites/internal/parse"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -144,30 +145,7 @@ func getNextDrawing(_ context.Context, doc extractor.Document) (*NextDrawing, er
|
||||
|
||||
// jackpot is in the format of "$1.5 billion", "$100 million", or "$200,000" etc
|
||||
|
||||
// make one filter to only get the numeric part of the jackpot
|
||||
|
||||
numericOnly := func(in string) float64 {
|
||||
var out string
|
||||
for _, r := range in {
|
||||
if r >= '0' && r <= '9' {
|
||||
out += string(r)
|
||||
}
|
||||
|
||||
if r == '.' {
|
||||
out += string(r)
|
||||
}
|
||||
}
|
||||
|
||||
val, err := strconv.ParseFloat(out, 64)
|
||||
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
numeric := numericOnly(txt)
|
||||
numeric := parse.NumericOnly(txt)
|
||||
|
||||
if strings.Contains(txt, "Billion") {
|
||||
nextDrawing.JackpotDollars = int(numeric * 1000000000)
|
||||
|
||||
Reference in New Issue
Block a user