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

View File

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