summaryrefslogtreecommitdiff
path: root/crawler/utility.go
diff options
context:
space:
mode:
authorhorus_arch2018-02-17 15:07:52 +0100
committerhorus_arch2018-02-17 15:07:52 +0100
commitfc83917d623228b09191f178062e59fad0722795 (patch)
treedd81ddee7f28550c974e27b60a0d0419a53b0c8d /crawler/utility.go
parentbcdea2f8e95f5305625a773223829478c8c13bed (diff)
downloadalkobote-fc83917d623228b09191f178062e59fad0722795.tar.gz
Adds crawler for whiskysite.nl. (crawler)
Diffstat (limited to 'crawler/utility.go')
-rw-r--r--crawler/utility.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/crawler/utility.go b/crawler/utility.go
index 29f14d6..f588c22 100644
--- a/crawler/utility.go
+++ b/crawler/utility.go
@@ -2,6 +2,7 @@ package main
import (
"errors"
+ "math"
"regexp"
"strconv"
"strings"
@@ -189,3 +190,16 @@ func get_base_price(e *colly.HTMLElement) (int, error) {
return base_price, nil
}
+
+/*
+ * Source: https://golang.org/src/math/floor.go?s=2165:2200#L104
+ * Will use std lib with go version >= 1.10
+ */
+func RoundToEven(x float64) float64 {
+ t := math.Trunc(x)
+ odd := math.Remainder(t, 2) != 0
+ if d := math.Abs(x - t); d > 0.5 || (d == 0.5 && odd) {
+ return t + math.Copysign(1, x)
+ }
+ return t
+}