summaryrefslogtreecommitdiff
path: root/crawler/shop_whic.go
diff options
context:
space:
mode:
authorhorus2018-02-16 18:06:50 +0100
committerhorus2018-02-16 18:06:50 +0100
commitbf5f6b98a1d933d5f0ffb7fe965428f4dab5e3b0 (patch)
treec95eb6426b61965b37da2b60da36cfe2c02a92b4 /crawler/shop_whic.go
parented6ab4da59f80bf9fa2cbf15da5c9167dff44ea4 (diff)
downloadalkobote-bf5f6b98a1d933d5f0ffb7fe965428f4dab5e3b0.tar.gz
Structured logging part two. (crawler)
Diffstat (limited to 'crawler/shop_whic.go')
-rw-r--r--crawler/shop_whic.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/crawler/shop_whic.go b/crawler/shop_whic.go
index e2bb6b9..e082ad1 100644
--- a/crawler/shop_whic.go
+++ b/crawler/shop_whic.go
@@ -1,7 +1,6 @@
package main
import (
- log "github.com/Sirupsen/logrus"
"regexp"
"strings"
@@ -37,13 +36,13 @@ 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 {
- log.Fatal(err)
+ Fatal(err, "Whic: 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, "Whic: Converting discounted price failed")
}
})
})
@@ -51,7 +50,7 @@ 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 {
- log.Fatal(err)
+ Fatal(err, "Whic: Sanitizing base price failed")
}
/*
@@ -61,13 +60,21 @@ func ScrapeWhic(shop Shop) []Angebot {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(img_link_noisy))
if err != nil {
- log.Fatal(err)
+ Fatal(err, "Whic: Parsing document in Goquery failed")
}
W.Image_url, _ = doc.Find("img").Attr("src")
e.Request.Visit(W.Url)
W.Volume = get_volume(e)
+ if W.Volume == 0 {
+ DebugOffer(W, "Whic: Volume is zero")
+ return
+ }
W.Abv = get_abv(e)
+ if W.Abv == 0 {
+ DebugOffer(W, "Whic: Abv is zero")
+ return
+ }
W.Shop = shop.Id
W.Spirit_type = "Whisky"
@@ -81,7 +88,7 @@ func ScrapeWhic(shop Shop) []Angebot {
r_volume, err := regexp.Compile("Volumen: ([0-9]+([.,][0-9]+)) Liter")
if err != nil {
- log.Fatal(err)
+ Fatal(err, "Whic: Volumen regex failed")
}
volume := r_volume.FindStringSubmatch(text_noisy)
if volume == nil || len(volume) < 2 {
@@ -92,7 +99,7 @@ func ScrapeWhic(shop Shop) []Angebot {
r_abv, err := regexp.Compile("Alkoholgehalt: ([0-9]+([.,][0-9]+))%")
if err != nil {
- log.Fatal(err)
+ Fatal(err, "Whic: Abv regex failed")
}
abv := r_abv.FindStringSubmatch(text_noisy)
if abv == nil || len(abv) < 2 {