Skip to content

Commit

Permalink
there exists two tipes of dashes lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieg0Code committed Aug 17, 2024
1 parent f7b4734 commit 2629f05
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions scraper/src/scraper/scraper_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,33 @@ type ScraperImpl struct {
Collector *colly.Collector
}

// CleanPrice implements Scraper.
// CleanPrice implements Scraper.
func (s *ScraperImpl) CleanPrice(price string) ([]int, error) {
cleaned := strings.ReplaceAll(price, "$", "")
cleaned = strings.ReplaceAll(cleaned, ".", "")
cleaned = strings.TrimSpace(cleaned) // Limpieza adicional
cleaned = strings.TrimSpace(cleaned)

if strings.Contains(cleaned, "\u2013") {
priceParts := strings.Split(cleaned, "\u2013")
if strings.Contains(cleaned, "") {
priceParts := strings.Split(cleaned, "")
var prices []int
for _, part := range priceParts {
part = strings.TrimSpace(part)
if part == "" {
logrus.WithError(errors.New("empty price part")).Error("empty price part")
return nil, errors.New("empty price part")
}
price, err := strconv.Atoi(part)
if err != nil {
logrus.WithError(err).Error("error converting price to int")
return nil, errors.New("error converting price to int")
logrus.WithError(err).Errorf("error converting price to int: %s", part)
continue // Skip this part instead of returning an error
}

prices = append(prices, price)
}

if len(prices) == 0 {
return nil, errors.New("no valid prices found")
}
return prices, nil
}

priceInt, err := strconv.Atoi(cleaned)
if err != nil {
logrus.WithError(err).Error("error converting price to int")
logrus.WithError(err).Errorf("error converting price to int: %s", cleaned)
return nil, errors.New("error converting price to int")
}

Expand Down

0 comments on commit 2629f05

Please sign in to comment.