Skip to content

Commit 2629f05

Browse files
committed
there exists two tipes of dashes lol
1 parent f7b4734 commit 2629f05

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

scraper/src/scraper/scraper_impl.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,33 @@ type ScraperImpl struct {
1515
Collector *colly.Collector
1616
}
1717

18-
// CleanPrice implements Scraper.
1918
// CleanPrice implements Scraper.
2019
func (s *ScraperImpl) CleanPrice(price string) ([]int, error) {
2120
cleaned := strings.ReplaceAll(price, "$", "")
2221
cleaned = strings.ReplaceAll(cleaned, ".", "")
23-
cleaned = strings.TrimSpace(cleaned) // Limpieza adicional
22+
cleaned = strings.TrimSpace(cleaned)
2423

25-
if strings.Contains(cleaned, "\u2013") {
26-
priceParts := strings.Split(cleaned, "\u2013")
24+
if strings.Contains(cleaned, "") {
25+
priceParts := strings.Split(cleaned, "")
2726
var prices []int
2827
for _, part := range priceParts {
2928
part = strings.TrimSpace(part)
30-
if part == "" {
31-
logrus.WithError(errors.New("empty price part")).Error("empty price part")
32-
return nil, errors.New("empty price part")
33-
}
3429
price, err := strconv.Atoi(part)
3530
if err != nil {
36-
logrus.WithError(err).Error("error converting price to int")
37-
return nil, errors.New("error converting price to int")
31+
logrus.WithError(err).Errorf("error converting price to int: %s", part)
32+
continue // Skip this part instead of returning an error
3833
}
39-
4034
prices = append(prices, price)
4135
}
42-
36+
if len(prices) == 0 {
37+
return nil, errors.New("no valid prices found")
38+
}
4339
return prices, nil
4440
}
4541

4642
priceInt, err := strconv.Atoi(cleaned)
4743
if err != nil {
48-
logrus.WithError(err).Error("error converting price to int")
44+
logrus.WithError(err).Errorf("error converting price to int: %s", cleaned)
4945
return nil, errors.New("error converting price to int")
5046
}
5147

0 commit comments

Comments
 (0)