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 _, 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))
}
}
}