diff --git a/README.md b/README.md index de1a56d..b576a8d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,25 @@ # fuelprices +## Summary +<<<<<<< HEAD ## Summary weather is a small program that fetch weather informations, and store them to influxdb ## Usage +======= +fuelprices is a small tool designed to fetch fuel prices from France open data and send them to influxdb + +## Howto + +### Build +>>>>>>> 329f1c7752d61b932e179be3884a1824a1393d6c ```shell -fuelprices -configfile fuelprices.ini +go build ``` -## Sample config +### Sample config in fuelprices.ini ```ini [fuelprices] @@ -24,14 +33,19 @@ pos=50000007 types=Gazole,SP95,SP98 [influxdb] -# Influxdb settings -hostname=influxdb -port=8086 +# InfluxDB settings +url=http://influxdb:8086/ username=influxdb password=password database=database ``` +### Run + +```shell +./fuelprices -configfile fuelprices.ini +``` + ## License ```text diff --git a/common.ini.sample b/common.ini.sample index 28fafc0..4b5fa5b 100644 --- a/common.ini.sample +++ b/common.ini.sample @@ -12,8 +12,7 @@ table=fuel_price [influxdb] # Influxdb settings -hostname=host -database=me -port=8086 +url=http://influxdb:8086/ username=influx -password=password \ No newline at end of file +password=password +database=me \ No newline at end of file diff --git a/functions.go b/functions.go index a1a5313..bb2b55f 100644 --- a/functions.go +++ b/functions.go @@ -48,8 +48,7 @@ func (fpc *FuelPricesConfig) GetConfig() error { } influxdbSection := config.Section("influxdb") - fpc.InfluxHost = influxdbSection.Key("hostname").MustString("localhost") - fpc.InfluxPort = influxdbSection.Key("port").MustInt(8086) + fpc.InfluxURL = influxdbSection.Key("url").MustString("http://localhost:8086") fpc.InfluxUser = influxdbSection.Key("username").MustString("username") fpc.InfluxPass = influxdbSection.Key("password").MustString("password") fpc.InfluxDB = influxdbSection.Key("database").MustString("me") @@ -74,7 +73,6 @@ func DownloadFile(fpc *FuelPricesConfig, zipfile *ZipFile) error { if err != nil { return err } - defer resp.Body.Close() zipfile.Content, err = ioutil.ReadAll(resp.Body) @@ -145,7 +143,7 @@ func GetPrices(fpc *FuelPricesConfig, prices *[]Price, xmlfile *XMLFile) error { // SendToInflux sends time series data to influxdb func SendToInflux(fpc *FuelPricesConfig, prices *[]Price) error { httpClient, err := client.NewHTTPClient(client.HTTPConfig{ - Addr: fmt.Sprintf("http://%s:%d", fpc.InfluxHost, fpc.InfluxPort), + Addr: fpc.InfluxURL, Username: fpc.InfluxUser, Password: fpc.InfluxPass, }) @@ -153,6 +151,8 @@ func SendToInflux(fpc *FuelPricesConfig, prices *[]Price) error { return err } + defer httpClient.Close() + bp, err := client.NewBatchPoints(client.BatchPointsConfig{ Database: fpc.InfluxDB, }) diff --git a/types.go b/types.go index 828825c..6b718bc 100644 --- a/types.go +++ b/types.go @@ -21,8 +21,7 @@ type FuelPricesConfig struct { Pos []string Types []string Table string - InfluxHost string - InfluxPort int + InfluxURL string InfluxUser string InfluxPass string InfluxDB string