diff options
| author | horus | 2018-06-16 13:52:18 +0200 |
|---|---|---|
| committer | horus | 2018-06-16 13:52:18 +0200 |
| commit | f9b561c087ccf5109928371192f0f5807103e296 (patch) | |
| tree | 65e12f395c1412963713d33728d0952507e47cba /crawler | |
| parent | 482ac52e2db7ca3db7005dcc01d21b69da0faf89 (diff) | |
| download | alkobote-f9b561c087ccf5109928371192f0f5807103e296.tar.gz | |
Adds support for cl. (crawler)
Diffstat (limited to 'crawler')
| -rw-r--r-- | crawler/utility.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/crawler/utility.go b/crawler/utility.go index 5fa78c4..0650546 100644 --- a/crawler/utility.go +++ b/crawler/utility.go @@ -81,12 +81,29 @@ func detect_spirit_type(name string) string { } func extract_volume(volume string) (float32, error) { - r_liter, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?[lL](iter)?`) + var volume_noisy string + var is_litre_instead_of_cl bool + + // difference between cl... + r_cl, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?[cC][lL]`) if err != nil { - Fatal(err, "Extract volume regex failed") + Fatal(err, "Extract volume (centiliter) regex failed") + } + + volume_noisy = r_cl.FindString(volume) + + if volume_noisy == "" { + // ...and litre + is_litre_instead_of_cl = true + + r_liter, err := regexp.Compile(`[0-9]+([,.][0-9]+)?( )?[lL](iter)?`) + if err != nil { + Fatal(err, "Extract volume regex failed") + } + volume_noisy = r_liter.FindString(volume) } - volume_noisy := r_liter.FindString(volume) + // extract numbers r_liter2, err := regexp.Compile(`[0-9]+([,.][0-9]+)?`) if err != nil { Fatal(err, "2nd extract volume regex failed") @@ -99,6 +116,11 @@ func extract_volume(volume string) (float32, error) { return 0, err } + // converting from cl to litre + if !is_litre_instead_of_cl { + volume64 = volume64 / 100 + } + return float32(volume64), err } |
