fixed error when fetching unused types of fuel

This commit is contained in:
Paul 2019-06-26 02:23:57 +02:00
parent a92d119b9d
commit af4e13adfa

View File

@ -110,17 +110,22 @@ func GetPrices(prices **[]Price, fpc *FuelPricesConfig, output *[]byte) error {
for _, station := range fpc.Pos { for _, station := range fpc.Pos {
for _, fuel := range fpc.Types { for _, fuel := range fpc.Types {
query := fmt.Sprintf(fpc.XPathBase, station, fuel) query := fmt.Sprintf(fpc.XPathBase, station, fuel)
list := xmlquery.FindOne(xml, query) list := xmlquery.FindOne(xml, query)
for _, i := range list.Attr { if list != nil {
if i.Name.Local == "valeur" { for _, i := range list.Attr {
var val float64 if i.Name.Local == "valeur" {
if s, err := strconv.ParseFloat(i.Value, 64); err == nil { var val float64
val = s 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))
} }
} }
} }