cleaned files, removed Makefile

This commit is contained in:
Paul 2019-06-06 00:04:51 +02:00
parent c49bcbce03
commit 6f1f685e65
3 changed files with 13 additions and 30 deletions

View File

@ -1,5 +0,0 @@
all: build
build: go build
clean: go clean

View File

@ -3,7 +3,6 @@ package main
import ( import (
"archive/zip" "archive/zip"
"fmt" "fmt"
"log"
"time" "time"
"flag" "flag"
@ -50,40 +49,37 @@ var sxml Srcfile
var ofile Outfile var ofile Outfile
var err error var err error
var zipfile *zip.Reader var zipfile *zip.Reader
var prices *[]Price
var now = time.Now()
var fpc FuelPricesConfig
var configpath string
func main() { func main() {
var fpc FuelPricesConfig
var configpath string
flag.StringVar(&configpath,"configfile","common.ini","config file to use with fuelprices section") flag.StringVar(&configpath,"configfile","common.ini","config file to use with fuelprices section")
flag.Parse() flag.Parse()
GetConfig(configpath, &fpc) GetConfig(configpath, &fpc)
sxml.Filename = fpc.RemoteFilename sxml.Filename = fpc.RemoteFilename
sxml.Filepath = fmt.Sprintf("%s/%s", fpc.TmpDir, sxml.Filename)
httpClient, err := client.NewHTTPClient(client.HTTPConfig{ httpClient, err := client.NewHTTPClient(client.HTTPConfig{
Addr: fmt.Sprintf("http://%s:%d", fpc.InfluxHost, fpc.InfluxPort), Addr: fmt.Sprintf("http://%s:%d", fpc.InfluxHost, fpc.InfluxPort),
Username: fpc.InfluxUser, Username: fpc.InfluxUser,
Password: fpc.InfluxPass, Password: fpc.InfluxPass,
}) })
HandleFatalError(err)
bp, err := client.NewBatchPoints(client.BatchPointsConfig{ bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: fpc.InfluxDB, Database: fpc.InfluxDB,
}) })
HandleFatalError(err)
err = DownloadFile(fpc.RemoteURL) err = DownloadFile(fpc.RemoteURL)
if err != nil { HandleFatalError(err)
log.Fatal("Unable to download file")
}
err = ExtractZip() err = ExtractZip()
if err != nil { HandleFatalError(err)
log.Fatal("Unable extract file")
}
var prices *[]Price
var now = time.Now()
GetPrices(&prices, fpc.Pos, fpc.Types, fpc.XPathBase) GetPrices(&prices, fpc.Pos, fpc.Types, fpc.XPathBase)
@ -103,5 +99,4 @@ func main() {
err = httpClient.Write(bp) err = httpClient.Write(bp)
HandleError(err) HandleError(err)
} }
} }

View File

@ -55,20 +55,13 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
// DownloadFile fetch file from webserver // DownloadFile fetch file from webserver
func DownloadFile(url string) error { func DownloadFile(url string) error {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { HandleError(err)
return err
}
szip.Content, err = ioutil.ReadAll(resp.Body) szip.Content, err = ioutil.ReadAll(resp.Body)
HandleError(err)
if err != nil {
return err
}
err = resp.Body.Close() err = resp.Body.Close()
if err != nil { HandleError(err)
return err
}
return err return err
} }
@ -82,7 +75,7 @@ func ExtractZip() error {
} }
for _, f := range zipfile.File { for _, f := range zipfile.File {
if f.Name == sxml.Filename { if f.Name == fpc.RemoteFilename {
rc, err := f.Open() rc, err := f.Open()
if err != nil { if err != nil {
return err return err