From f6904aab20e2d09255fd0adabfd246165ff3cb02 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 8 Feb 2018 18:26:41 +0100 Subject: Crawler extracts volume, price per litre and abv. (MC Whisky, Rum & Co, Whic) --- crawler/convert_price.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crawler/convert_price.go') diff --git a/crawler/convert_price.go b/crawler/convert_price.go index d9725a0..a76c067 100644 --- a/crawler/convert_price.go +++ b/crawler/convert_price.go @@ -2,6 +2,8 @@ package main import ( "errors" + "log" + "regexp" "strconv" "strings" ) @@ -28,6 +30,12 @@ func convert_price(price string) (int, error) { price = strings.TrimSuffix(strings.ToLower(price), "euro") price = strings.TrimSpace(price) + r, err := regexp.Compile(`[0-9]+([.,][0-9]+)?`) + if err != nil { + return 0, err + } + price = r.FindString(price) + if len(price) < 2 { price = "00" + price } else if len(price) < 3 { @@ -90,6 +98,7 @@ func convert_price(price string) (int, error) { */ price_int, err := strconv.Atoi(price) if err != nil { + log.Println(price) return 0, err } -- cgit v1.2.3