summaryrefslogtreecommitdiff
path: root/crawler/utility.go
diff options
context:
space:
mode:
authorMax2018-02-08 18:26:41 +0100
committerMax2018-02-08 18:26:41 +0100
commitf6904aab20e2d09255fd0adabfd246165ff3cb02 (patch)
treef7ac27cb5dd34443640235a97ce9bde8f2a1816a /crawler/utility.go
parentae7ed42df6a55e36c82b88e7c71569951847a68c (diff)
downloadalkobote-f6904aab20e2d09255fd0adabfd246165ff3cb02.tar.gz
Crawler extracts volume, price per litre and abv. (MC Whisky, Rum & Co, Whic)
Diffstat (limited to 'crawler/utility.go')
-rw-r--r--crawler/utility.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/crawler/utility.go b/crawler/utility.go
index a794c4b..9de7845 100644
--- a/crawler/utility.go
+++ b/crawler/utility.go
@@ -5,6 +5,8 @@ import (
"regexp"
"strconv"
"strings"
+
+ "github.com/gocolly/colly"
)
func detect_spirit_type(name string) string {
@@ -47,6 +49,7 @@ func extract_volume(volume string) (float32, error) {
if err != nil {
return 0, err
}
+
return float32(volume64), err
}
@@ -61,5 +64,51 @@ func extract_abv(abv_noisy string) (float32, error) {
if err != nil {
return 0, err
}
+
return float32(abv64), nil
}
+
+/*
+ * In litre, but float.
+ */
+func get_volume(e *colly.HTMLElement) float32 {
+
+ volume_noisy := e.Request.Ctx.Get("volume")
+
+ matched, err := regexp.MatchString(`[lL](iter)?`, volume_noisy)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if !matched {
+ log.Println("get_volume: not matched: " + volume_noisy)
+ return 0
+ }
+
+ volume, err := extract_volume(volume_noisy)
+ if err != nil {
+ log.Println("get_volume: " + volume_noisy)
+ log.Fatal(err)
+ }
+
+ return volume
+}
+
+/*
+ * In procent. (float)
+ */
+func get_abv(e *colly.HTMLElement) float32 {
+
+ abv_noisy := e.Request.Ctx.Get("abv")
+
+ if abv_noisy == "" {
+ return 0
+ }
+
+ abv, err := extract_abv(abv_noisy)
+ if err != nil {
+ log.Println("get_abv: " + abv_noisy)
+ log.Fatal(err)
+ }
+
+ return abv
+}