diff options
| author | horus_arch | 2018-02-17 13:51:35 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-17 13:51:35 +0100 |
| commit | bcdea2f8e95f5305625a773223829478c8c13bed (patch) | |
| tree | efac40b03131b4f9e43de848920695ee785a0a3f /crawler/shop_mcwhisky.go | |
| parent | 9ebf51364773dae6db4c0c47d77710c9f1a37b51 (diff) | |
| download | alkobote-bcdea2f8e95f5305625a773223829478c8c13bed.tar.gz | |
Introduces context on errors. (crawler)
Diffstat (limited to 'crawler/shop_mcwhisky.go')
| -rw-r--r-- | crawler/shop_mcwhisky.go | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/crawler/shop_mcwhisky.go b/crawler/shop_mcwhisky.go index b423c72..c015d26 100644 --- a/crawler/shop_mcwhisky.go +++ b/crawler/shop_mcwhisky.go @@ -6,7 +6,7 @@ import ( "github.com/gocolly/colly" ) -func ScrapeMCWhisky(shop Shop) []Angebot { +func (app *App) ScrapeMCWhisky(shop Shop) []Angebot { Shop_url := "https://www.mcwhisky.com/whisky/whisky-sonderangebote.html" Whiskys := []Angebot{} @@ -35,13 +35,19 @@ func ScrapeMCWhisky(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, "MC Whisky: Converting original price failed") + W.error_msg = err.Error() + W.error_ctx = e.ChildText(".price") + WarnOffer(W, "MC Whisky: 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, "MC Whisky: Converting discounted price failed") + W.error_msg = err.Error() + W.error_ctx = e.ChildText(".price") + WarnOffer(W, "MC Whisky: Converting discounted price failed") + return } }) }) @@ -49,21 +55,29 @@ func ScrapeMCWhisky(shop Shop) []Angebot { price_per_litre_noisy := e.ChildText(".price-box-extended-info-ppl") W.Base_price, err = sanitize_base_price(price_per_litre_noisy) if err != nil { - Fatal(err, "MC Whisky: Sanitizing base price failed") + W.error_msg = err.Error() + W.error_ctx = price_per_litre_noisy + WarnOffer(W, "MC Whisky: Sanitizing base price failed") + return } W.Image_url = e.ChildAttr("img", "src") e.Request.Visit(W.Url) - W.Volume = get_volume(e) + var ctx string + W.Volume, ctx = get_volume(e) if W.Abv == 0 { - DebugOffer(W, "MC Whisky: Volume is zero") + W.error_msg = "MC Whisky: Volume is zero" + W.error_ctx = ctx + WarnOffer(W, "MC Whisky: Volume is zero") return } - W.Abv = get_abv(e) + W.Abv, ctx = get_abv(e) if W.Abv == 0 { - DebugOffer(W, "MC Whisky: Abv is zero") + W.error_msg = "MC Whisky: Abv is zero" + W.error_ctx = ctx + WarnOffer(W, "MC Whisky: Abv is zero") return } |
