From af4e13adfa708539ee07e0fe4eec44755102ce32 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 26 Jun 2019 02:23:57 +0200 Subject: [PATCH] fixed error when fetching unused types of fuel --- functions.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/functions.go b/functions.go index 4f0d4d8..b225ab0 100644 --- a/functions.go +++ b/functions.go @@ -110,17 +110,22 @@ func GetPrices(prices **[]Price, fpc *FuelPricesConfig, output *[]byte) error { for _, station := range fpc.Pos { for _, fuel := range fpc.Types { + query := fmt.Sprintf(fpc.XPathBase, station, fuel) list := xmlquery.FindOne(xml, query) - for _, i := range list.Attr { - if i.Name.Local == "valeur" { - var val float64 - if s, err := strconv.ParseFloat(i.Value, 64); err == nil { - val = s + if list != nil { + for _, i := range list.Attr { + if i.Name.Local == "valeur" { + var val float64 + if s, err := strconv.ParseFloat(i.Value, 64); err == nil { + val = s + } + pr = append(pr, Price{ID: station, Fuel: fuel, Amount: val}) } - pr = append(pr, Price{ID: station, Fuel: fuel, Amount: val}) } + } else { + log.Println(fmt.Sprintf("Fuel type not found for point of sale, skipping. Query : %s", query)) } } }