2019-06-05 21:48:21 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/zip"
|
2019-06-06 12:09:02 +02:00
|
|
|
"flag"
|
2019-06-05 21:48:21 +02:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2019-06-05 22:58:16 +02:00
|
|
|
_ "github.com/influxdata/influxdb1-client"
|
2019-06-05 21:48:21 +02:00
|
|
|
client "github.com/influxdata/influxdb1-client/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var szip Srcfile
|
|
|
|
var sxml Srcfile
|
|
|
|
var ofile Outfile
|
|
|
|
var err error
|
|
|
|
var zipfile *zip.Reader
|
2019-06-06 00:04:51 +02:00
|
|
|
var prices *[]Price
|
|
|
|
var now = time.Now()
|
|
|
|
var fpc FuelPricesConfig
|
|
|
|
var configpath string
|
|
|
|
|
2019-06-05 21:48:21 +02:00
|
|
|
func main() {
|
|
|
|
|
2019-06-06 12:09:02 +02:00
|
|
|
flag.StringVar(&configpath, "configfile", "common.ini", "config file to use with fuelprices section")
|
|
|
|
flag.Parse()
|
2019-06-05 23:50:39 +02:00
|
|
|
GetConfig(configpath, &fpc)
|
2019-06-05 21:48:21 +02:00
|
|
|
|
|
|
|
sxml.Filename = fpc.RemoteFilename
|
|
|
|
|
|
|
|
httpClient, err := client.NewHTTPClient(client.HTTPConfig{
|
|
|
|
Addr: fmt.Sprintf("http://%s:%d", fpc.InfluxHost, fpc.InfluxPort),
|
|
|
|
Username: fpc.InfluxUser,
|
|
|
|
Password: fpc.InfluxPass,
|
|
|
|
})
|
2019-06-06 12:09:02 +02:00
|
|
|
HandleFatalError(err)
|
2019-06-05 21:48:21 +02:00
|
|
|
|
|
|
|
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
|
|
|
|
Database: fpc.InfluxDB,
|
|
|
|
})
|
2019-06-06 12:09:02 +02:00
|
|
|
HandleFatalError(err)
|
2019-06-05 21:48:21 +02:00
|
|
|
|
|
|
|
err = DownloadFile(fpc.RemoteURL)
|
2019-06-06 12:09:02 +02:00
|
|
|
HandleFatalError(err)
|
2019-06-05 21:48:21 +02:00
|
|
|
|
|
|
|
err = ExtractZip()
|
2019-06-06 12:09:02 +02:00
|
|
|
HandleFatalError(err)
|
2019-06-05 21:48:21 +02:00
|
|
|
|
|
|
|
GetPrices(&prices, fpc.Pos, fpc.Types, fpc.XPathBase)
|
|
|
|
|
|
|
|
for _, p := range *prices {
|
|
|
|
|
2019-06-05 23:03:40 +02:00
|
|
|
tags := map[string]string{"pdv": p.ID, "fuel": p.Fuel}
|
2019-06-05 21:48:21 +02:00
|
|
|
fields := map[string]interface{}{"value": p.Amount}
|
|
|
|
|
|
|
|
point, _ := client.NewPoint(
|
2019-06-09 13:40:19 +02:00
|
|
|
fpc.InfluxTable,
|
2019-06-05 21:48:21 +02:00
|
|
|
tags,
|
|
|
|
fields,
|
|
|
|
now,
|
|
|
|
)
|
|
|
|
|
|
|
|
bp.AddPoint(point)
|
|
|
|
err = httpClient.Write(bp)
|
|
|
|
HandleError(err)
|
|
|
|
}
|
|
|
|
}
|