summaryrefslogtreecommitdiff
path: root/sanitize_price.go
diff options
context:
space:
mode:
authorMax2018-02-06 00:35:39 +0100
committerMax2018-02-06 00:35:39 +0100
commit71950479fbd6088f249e5fda3b180f294d1d745d (patch)
tree06f360a7e02b7e0011bda815fa102ec54ae8d0ec /sanitize_price.go
parent13a807854bf4d0258723ec3152b217ed4cf8e051 (diff)
downloadalkobote-71950479fbd6088f249e5fda3b180f294d1d745d.tar.gz
Moves crawler to designated directory.
Diffstat (limited to 'sanitize_price.go')
-rw-r--r--sanitize_price.go103
1 files changed, 0 insertions, 103 deletions
diff --git a/sanitize_price.go b/sanitize_price.go
deleted file mode 100644
index 2052842..0000000
--- a/sanitize_price.go
+++ /dev/null
@@ -1,103 +0,0 @@
-package main
-
-import (
- "errors"
- "strconv"
- "strings"
-)
-
-func sanitize_price(price string) (int, error) {
- if "" == price {
- return 0, errors.New("Empty string")
- }
-
- multiply_by_10 := false
- multiply_by_100 := true
-
- price = strings.TrimSpace(price)
-
- price = strings.TrimPrefix(price, "€")
- price = strings.TrimSpace(price)
-
- price = strings.TrimSuffix(price, "€")
- price = strings.TrimSpace(price)
-
- price = strings.TrimSuffix(strings.ToLower(price), "eur")
- price = strings.TrimSpace(price)
-
- price = strings.TrimSuffix(strings.ToLower(price), "euro")
- price = strings.TrimSpace(price)
-
- if len(price) < 2 {
- price = "0" + price
- } else if len(price) < 3 {
- price = "00" + price
- }
-
- c := string(price[len(price)-2:])
- c = string(c[0:1])
-
- /*
- Extracts the second last char and checks if it's a "." or a ",".
- */
- if "," == c {
- if strings.Count(price, ",") > 1 {
- return 0, errors.New("Invalid format")
- }
-
- multiply_by_10 = true
- multiply_by_100 = false
-
- } else if "." == c {
- if strings.Count(price, ".") > 1 {
- return 0, errors.New("Invalid format")
- }
-
- multiply_by_10 = true
- multiply_by_100 = false
-
- }
-
- c = string(price[len(price)-3:])
- c = string(c[0:1])
-
- /*
- Extracts the third last char and checks if it's a "." or a ",".
- */
- if "," == c {
- if strings.Count(price, ",") > 1 {
- return 0, errors.New("Invalid format")
- }
-
- multiply_by_10 = false
- multiply_by_100 = false
-
- } else if "." == c {
- if strings.Count(price, ".") > 1 {
- return 0, errors.New("Invalid format")
- }
-
- multiply_by_10 = false
- multiply_by_100 = false
-
- }
-
- price = strings.Replace(price, ",", "", -1)
- price = strings.Replace(price, ".", "", -1)
-
- /*
- Casts the price to integer in cents (not euro!).
- */
- price_int, err := strconv.Atoi(price)
- if err != nil {
- return 0, err
- }
-
- if multiply_by_10 {
- price_int = price_int * 10
- } else if multiply_by_100 {
- price_int = price_int * 100
- }
-
- return price_int, nil
-}