summaryrefslogtreecommitdiff
path: root/crawler/shop_mcwhisky.go
diff options
context:
space:
mode:
authorhorus_arch2018-02-17 16:24:31 +0100
committerhorus_arch2018-02-17 16:24:31 +0100
commit2394367da917f35cbe45fba10b05493f2c3fa6db (patch)
tree8dbea173da082b86c8bfacdbee1c854e10e42478 /crawler/shop_mcwhisky.go
parent0260f772fcaf627d4b4c3611b46a8db02cb76f8b (diff)
downloadalkobote-2394367da917f35cbe45fba10b05493f2c3fa6db.tar.gz
Add error context for MC Whisky. (crawler)
Diffstat (limited to 'crawler/shop_mcwhisky.go')
-rw-r--r--crawler/shop_mcwhisky.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/crawler/shop_mcwhisky.go b/crawler/shop_mcwhisky.go
index c015d26..0c35eff 100644
--- a/crawler/shop_mcwhisky.go
+++ b/crawler/shop_mcwhisky.go
@@ -65,6 +65,21 @@ func (app *App) ScrapeMCWhisky(shop Shop) []Angebot {
e.Request.Visit(W.Url)
+ volume_failed := e.Request.Ctx.Get("volume_failed")
+ if volume_failed != "" {
+ W.error_msg = "MC Whisky: Volume failed"
+ W.error_ctx = volume_failed
+ WarnOffer(W, "MC Whisky: Volume failed")
+ return
+ }
+ abv_failed := e.Request.Ctx.Get("abv_failed")
+ if volume_failed != "" {
+ W.error_msg = "MC Whisky: Abv failed"
+ W.error_ctx = abv_failed
+ WarnOffer(W, "MC Whisky: Abv failed")
+ return
+ }
+
var ctx string
W.Volume, ctx = get_volume(e)
if W.Abv == 0 {
@@ -96,15 +111,24 @@ func (app *App) ScrapeMCWhisky(shop Shop) []Angebot {
if err != nil {
Fatal(err, "MC Whisky: ABV regex failed")
}
+ abv := r_abv.FindString(text_noisy)
+ if abv == "" {
+ e.Request.Ctx.Put("abv_fail", text_noisy)
+ return
+ }
- e.Request.Ctx.Put("abv", r_abv.FindString(text_noisy))
+ e.Request.Ctx.Put("abv", abv)
r_volume, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?Liter$`)
if err != nil {
Fatal(err, "MC Whisky: Volume regex failed")
}
-
- e.Request.Ctx.Put("volume", r_volume.FindString(text_noisy))
+ volume := r_volume.FindString(text_noisy)
+ if volume == "" {
+ e.Request.Ctx.Put("volume_fail", text_noisy)
+ return
+ }
+ e.Request.Ctx.Put("volume", volume)
e.Request.Ctx.Put("website", string(e.Response.Body))
})