From 2629f054bd017f01e346aea70a0a5299c0ed3580 Mon Sep 17 00:00:00 2001 From: Dieg0Code Date: Sat, 17 Aug 2024 02:46:57 -0400 Subject: [PATCH] there exists two tipes of dashes lol --- scraper/src/scraper/scraper_impl.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/scraper/src/scraper/scraper_impl.go b/scraper/src/scraper/scraper_impl.go index a402d27..8a83c0f 100644 --- a/scraper/src/scraper/scraper_impl.go +++ b/scraper/src/scraper/scraper_impl.go @@ -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") }