From bf5f6b98a1d933d5f0ffb7fe965428f4dab5e3b0 Mon Sep 17 00:00:00 2001 From: horus Date: Fri, 16 Feb 2018 18:06:50 +0100 Subject: Structured logging part two. (crawler) --- crawler/shop_mcwhisky.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'crawler/shop_mcwhisky.go') diff --git a/crawler/shop_mcwhisky.go b/crawler/shop_mcwhisky.go index 165d944..b423c72 100644 --- a/crawler/shop_mcwhisky.go +++ b/crawler/shop_mcwhisky.go @@ -1,11 +1,8 @@ package main import ( - log "github.com/Sirupsen/logrus" "regexp" - // "strings" - // "github.com/PuerkitoBio/goquery" "github.com/gocolly/colly" ) @@ -38,13 +35,13 @@ 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 { - log.Fatal(err) + Fatal(err, "MC Whisky: Converting original price failed") } }) e.ForEach(".special-price", func(i int, e *colly.HTMLElement) { W.Discounted_price, err = convert_price(e.ChildText(".price")) if err != nil { - log.Fatal(err) + Fatal(err, "MC Whisky: Converting discounted price failed") } }) }) @@ -52,7 +49,7 @@ 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 { - log.Fatal(err) + Fatal(err, "MC Whisky: Sanitizing base price failed") } W.Image_url = e.ChildAttr("img", "src") @@ -60,7 +57,15 @@ func ScrapeMCWhisky(shop Shop) []Angebot { e.Request.Visit(W.Url) W.Volume = get_volume(e) + if W.Abv == 0 { + DebugOffer(W, "MC Whisky: Volume is zero") + return + } W.Abv = get_abv(e) + if W.Abv == 0 { + DebugOffer(W, "MC Whisky: Abv is zero") + return + } W.Shop = shop.Id W.Spirit_type = "Whisky" @@ -75,14 +80,14 @@ func ScrapeMCWhisky(shop Shop) []Angebot { r_abv, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?%`) if err != nil { - log.Fatal(err) + Fatal(err, "MC Whisky: ABV regex failed") } e.Request.Ctx.Put("abv", r_abv.FindString(text_noisy)) r_volume, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?Liter$`) if err != nil { - log.Fatal(err) + Fatal(err, "MC Whisky: Volume regex failed") } e.Request.Ctx.Put("volume", r_volume.FindString(text_noisy)) -- cgit v1.2.3