updated fuelprices

This commit is contained in:
Paul 2019-06-09 13:40:19 +02:00
parent d591cdcb76
commit 7e0328028b
3 changed files with 43 additions and 42 deletions

View File

@ -10,40 +10,6 @@ import (
client "github.com/influxdata/influxdb1-client/v2"
)
// Srcfile source file
type Srcfile struct {
Filename string
Filepath string
Content []byte
}
// Outfile is the output XML file
type Outfile struct {
Content []byte
}
// FuelPricesConfig is the main configuration
type FuelPricesConfig struct {
RemoteURL string
RemoteFilename string
XPathBase string
Pos []string
Types []string
TmpDir string
InfluxHost string
InfluxPort int
InfluxUser string
InfluxPass string
InfluxDB string
}
// Price contains price of points of sale
type Price struct {
ID string
Fuel string
Amount float64
}
var szip Srcfile
var sxml Srcfile
var ofile Outfile
@ -88,7 +54,7 @@ func main() {
fields := map[string]interface{}{"value": p.Amount}
point, _ := client.NewPoint(
"fuel_price",
fpc.InfluxTable,
tags,
fields,
now,

View File

@ -10,7 +10,6 @@ import (
"net/http"
"os"
"strconv"
"strings"
"github.com/antchfx/xmlquery"
"gopkg.in/ini.v1"
@ -43,9 +42,10 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
HandleError(err)
fpc.InfluxDB = fuelpricesSection.Key("influx_db").String()
fpc.InfluxTable = fuelpricesSection.Key("influx_table").String()
fpc.Pos = strings.Split(fuelpricesSection.Key("pos").String(), ",")
fpc.Types = strings.Split(fuelpricesSection.Key("types").String(), ",")
fpc.Pos = fuelpricesSection.Key("pos").Strings(",")
fpc.Types = fuelpricesSection.Key("types").Strings(",")
*fuelpricesconfig = fpc
@ -55,13 +55,13 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
// DownloadFile fetch file from webserver
func DownloadFile(url string) error {
resp, err := http.Get(url)
HandleError(err)
HandleError(err)
szip.Content, err = ioutil.ReadAll(resp.Body)
HandleError(err)
HandleError(err)
err = resp.Body.Close()
HandleError(err)
HandleError(err)
return err
}
@ -136,7 +136,6 @@ func HandleFatalError(err error) {
// Usage displays possible arguments
func Usage() {
fmt.Fprintf(os.Stderr, "Usage: fuelprices [configfile]\n")
flag.PrintDefaults()
os.Exit(1)
}

36
types.go Normal file
View File

@ -0,0 +1,36 @@
package main
// Srcfile source file
type Srcfile struct {
Filename string
Filepath string
Content []byte
}
// Outfile is the output XML file
type Outfile struct {
Content []byte
}
// FuelPricesConfig is the main configuration
type FuelPricesConfig struct {
RemoteURL string
RemoteFilename string
XPathBase string
Pos []string
Types []string
TmpDir string
InfluxHost string
InfluxPort int
InfluxUser string
InfluxPass string
InfluxDB string
InfluxTable string
}
// Price contains price of points of sale
type Price struct {
ID string
Fuel string
Amount float64
}