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_whiskyworld.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'crawler/shop_whiskyworld.go') diff --git a/crawler/shop_whiskyworld.go b/crawler/shop_whiskyworld.go index 9b968a3..5235d3c 100644 --- a/crawler/shop_whiskyworld.go +++ b/crawler/shop_whiskyworld.go @@ -1,7 +1,6 @@ package main import ( - log "github.com/Sirupsen/logrus" "strings" "github.com/gocolly/colly" @@ -43,15 +42,13 @@ func ScrapeWhiskyworld(shop Shop) []Angebot { W.Original_price, err = convert_price(regular_price) if err != nil { - log.Println("Whisky World: Original_price failed: " + regular_price + " // " + W.Name + " // " + W.Url + " // " + e.Request.URL.String()) - log.Fatal(err) + Fatal(err, "Whiskyworld: Converting original price failed") return } W.Discounted_price, err = convert_price(e.ChildText(".uvp")) if err != nil { - log.Println("Whisky World: Discounted_price failed") - log.Fatal(err) + Fatal(err, "Whiskyworld: Converting discounted price failed") return } @@ -59,13 +56,13 @@ func ScrapeWhiskyworld(shop Shop) []Angebot { text_noisy := e.ChildText(".item-inh") W.Volume, err = extract_volume(text_noisy) if err != nil { - log.Fatal(err) + Fatal(err, "Whiskyworld: Extracting volume failed") } abv_noisy := strings.TrimSpace(strings.SplitAfter(text_noisy, "Liter")[1]) abv_noisy = strings.TrimPrefix(abv_noisy, "/") W.Abv, err = extract_abv(abv_noisy) if err != nil { - log.Fatal(err) + Fatal(err, "Whiskyworld: Extracting abv failed") } }) @@ -75,8 +72,7 @@ func ScrapeWhiskyworld(shop Shop) []Angebot { base_price_noisy = strings.TrimSpace(strings.SplitAfter(base_price_noisy, "Liter")[0]) W.Base_price, err = sanitize_base_price(base_price_noisy) if err != nil { - log.Println("Whisky World: Base_price failed") - log.Fatal(err) + Fatal(err, "Whiskyworld: Sanitizing base price failed") } } @@ -87,6 +83,15 @@ func ScrapeWhiskyworld(shop Shop) []Angebot { W.Shop = shop.Id W.Spirit_type = "Whisky" + if W.Volume == 0 { + DebugOffer(W, "Whiskyworld: Volume is zero") + return + } + if W.Abv == 0 { + DebugOffer(W, "Whiskyworld: Abv is zero") + return + } + e.Request.Visit(W.Url) W.Website = e.Request.Ctx.Get("website") -- cgit v1.2.3