summaryrefslogtreecommitdiff
path: root/crawler/shop_mcwhisky.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_mcwhisky.go
parented6ab4da59f80bf9fa2cbf15da5c9167dff44ea4 (diff)
downloadalkobote-bf5f6b98a1d933d5f0ffb7fe965428f4dab5e3b0.tar.gz
Structured logging part two. (crawler)
Diffstat (limited to 'crawler/shop_mcwhisky.go')
-rw-r--r--crawler/shop_mcwhisky.go21
1 files changed, 13 insertions, 8 deletions
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))