diff options
Diffstat (limited to 'crawler/shop_whic.go')
| -rw-r--r-- | crawler/shop_whic.go | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/crawler/shop_whic.go b/crawler/shop_whic.go index e082ad1..0e7cdf9 100644 --- a/crawler/shop_whic.go +++ b/crawler/shop_whic.go @@ -8,7 +8,7 @@ import ( "github.com/gocolly/colly" ) -func ScrapeWhic(shop Shop) []Angebot { +func (app *App) ScrapeWhic(shop Shop) []Angebot { Shop_url := "https://whic.de/angebote" Whiskys := []Angebot{} @@ -36,13 +36,19 @@ func ScrapeWhic(shop Shop) []Angebot { e.ForEach(".old-price", func(i int, e *colly.HTMLElement) { W.Original_price, err = convert_price(e.ChildText(".price")) if err != nil { - Fatal(err, "Whic: Converting original price failed") + W.error_msg = err.Error() + W.error_ctx = e.ChildText(".price") + WarnOffer(W, "Whic: Converting original price failed") + return } }) e.ForEach(".special-price", func(i int, e *colly.HTMLElement) { W.Discounted_price, err = convert_price(e.ChildText(".price")) if err != nil { - Fatal(err, "Whic: Converting discounted price failed") + W.error_msg = err.Error() + W.error_ctx = e.ChildText(".price") + WarnOffer(W, "Whic: Converting discounted price failed") + return } }) }) @@ -50,7 +56,10 @@ func ScrapeWhic(shop Shop) []Angebot { base_price_noisy := e.ChildText(".base-price") W.Base_price, err = sanitize_base_price(base_price_noisy) if err != nil { - Fatal(err, "Whic: Sanitizing base price failed") + W.error_msg = err.Error() + W.error_ctx = base_price_noisy + WarnOffer(W, "Whic: Sanitizing base price failed") + return } /* @@ -60,19 +69,27 @@ func ScrapeWhic(shop Shop) []Angebot { doc, err := goquery.NewDocumentFromReader(strings.NewReader(img_link_noisy)) if err != nil { - Fatal(err, "Whic: Parsing document in Goquery failed") + W.error_msg = err.Error() + W.error_ctx = img_link_noisy + FatalOffer(W, "Whic: Parsing document in Goquery failed") } W.Image_url, _ = doc.Find("img").Attr("src") e.Request.Visit(W.Url) - W.Volume = get_volume(e) + + var ctx string + W.Volume, ctx = get_volume(e) if W.Volume == 0 { - DebugOffer(W, "Whic: Volume is zero") + W.error_msg = "Whic: Volume is zero" + W.error_ctx = ctx + WarnOffer(W, "Whic: Volume is zero") return } - W.Abv = get_abv(e) + W.Abv, ctx = get_abv(e) if W.Abv == 0 { - DebugOffer(W, "Whic: Abv is zero") + W.error_msg = "Whic: Abv is zero" + W.error_ctx = ctx + WarnOffer(W, "Whic: Abv is zero") return } |
