2019-07-07 13:09:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2019-07-14 21:44:57 +02:00
|
|
|
"fmt"
|
2019-07-14 21:10:20 +02:00
|
|
|
"log"
|
2019-07-07 13:09:55 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
_ "github.com/influxdata/influxdb1-client"
|
|
|
|
)
|
|
|
|
|
|
|
|
var wc WeatherConfig
|
|
|
|
var configpath string
|
2019-07-15 01:04:07 +02:00
|
|
|
var err error
|
|
|
|
var now = time.Now()
|
2019-07-07 13:09:55 +02:00
|
|
|
|
|
|
|
const kelvin = -273.15
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2019-07-24 00:36:37 +02:00
|
|
|
flag.StringVar(&configpath, "configfile", "weather.ini", "config file to use with fuelprices section")
|
2019-07-07 13:09:55 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
2019-07-14 21:10:20 +02:00
|
|
|
err := GetConfig(configpath, &wc)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-07-07 13:09:55 +02:00
|
|
|
|
2019-07-14 21:10:20 +02:00
|
|
|
for _, city := range wc.WeatherCities {
|
2019-07-14 21:44:57 +02:00
|
|
|
d, err := FetchData(city)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-07-15 01:16:36 +02:00
|
|
|
err = SendToInflux(&wc, d)
|
2019-07-14 21:44:57 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
} else {
|
2019-07-15 01:16:36 +02:00
|
|
|
log.Println(fmt.Sprintf("Successfully sent data for %s", city))
|
2019-07-14 21:44:57 +02:00
|
|
|
}
|
2019-07-07 13:09:55 +02:00
|
|
|
}
|
|
|
|
}
|