summaryrefslogtreecommitdiff
path: root/crawler/utility.go
diff options
context:
space:
mode:
authorhorus_arch2018-02-17 13:51:35 +0100
committerhorus_arch2018-02-17 13:51:35 +0100
commitbcdea2f8e95f5305625a773223829478c8c13bed (patch)
treeefac40b03131b4f9e43de848920695ee785a0a3f /crawler/utility.go
parent9ebf51364773dae6db4c0c47d77710c9f1a37b51 (diff)
downloadalkobote-bcdea2f8e95f5305625a773223829478c8c13bed.tar.gz
Introduces context on errors. (crawler)
Diffstat (limited to 'crawler/utility.go')
-rw-r--r--crawler/utility.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/crawler/utility.go b/crawler/utility.go
index 3c587b9..29f14d6 100644
--- a/crawler/utility.go
+++ b/crawler/utility.go
@@ -1,7 +1,7 @@
package main
import (
- log "github.com/Sirupsen/logrus"
+ "errors"
"regexp"
"strconv"
"strings"
@@ -131,7 +131,7 @@ func extract_abv(abv_noisy string) (float32, error) {
/*
* In litre, but float.
*/
-func get_volume(e *colly.HTMLElement) float32 {
+func get_volume(e *colly.HTMLElement) (float32, string) {
volume_noisy := e.Request.Ctx.Get("volume")
@@ -140,8 +140,7 @@ func get_volume(e *colly.HTMLElement) float32 {
Fatal(err, "Get volume regex failed")
}
if !matched {
- log.Debug("get_volume: not matched: " + volume_noisy)
- return 0
+ return 0, volume_noisy
}
volume, err := extract_volume(volume_noisy)
@@ -149,18 +148,18 @@ func get_volume(e *colly.HTMLElement) float32 {
Fatal(err, "Get Volume: Extract Volume failed: "+volume_noisy)
}
- return volume
+ return volume, ""
}
/*
* In procent. (float)
*/
-func get_abv(e *colly.HTMLElement) float32 {
+func get_abv(e *colly.HTMLElement) (float32, string) {
abv_noisy := e.Request.Ctx.Get("abv")
if abv_noisy == "" {
- return 0
+ return 0, abv_noisy
}
// abv_noisy = strings.Replace(abv_noisy, ".", ",", 1)
@@ -169,24 +168,24 @@ func get_abv(e *colly.HTMLElement) float32 {
Fatal(err, "Get ABV: Extract ABV failed: "+abv_noisy)
}
- return abv
+ return abv, ""
}
/*
* In cents. (int)
*/
-func get_base_price(e *colly.HTMLElement) int {
+func get_base_price(e *colly.HTMLElement) (int, error) {
base_price_noisy := e.Request.Ctx.Get("base_price")
if base_price_noisy == "" {
- return 0
+ return 0, errors.New("Base price empty")
}
base_price, err := sanitize_base_price(base_price_noisy)
if err != nil {
- Fatal(err, "Get base price: sanitize base price failed")
+ return 0, err
}
- return base_price
+ return base_price, nil
}