Skip to content

Commit

Permalink
feat(stability): improve url resolving / make the bot more robust (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb4L authored Apr 19, 2023
1 parent 0c188b4 commit 1731e59
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func parseDailyOffer() (dailyOffer, error) {
e.ForEach(
"a", func(i int, h *colly.HTMLElement) {
href := h.Attr("href")
if strings.HasPrefix(href, "/en/product/") && offer.URL == "" {
if strings.Contains(href, "/product/") && offer.URL == "" {
offer.URL = "https://digitec.ch" + href
}
},
Expand Down Expand Up @@ -118,8 +118,11 @@ func parseDailyOffer() (dailyOffer, error) {

logger.Println("found offer ", offer)
var err error
if offer.ItemName == "" || offer.PriceInformation == "" || offer.URL == "" {
if offer.ItemName == "" || offer.PriceInformation == "" {
err = fmt.Errorf("could not retrieve all values %s", offer)
}
if offer.URL == "" {
offer.URL = URL
}
return offer, err
}

0 comments on commit 1731e59

Please sign in to comment.