added units config variable

This commit is contained in:
Paul 2020-02-16 11:44:27 +01:00
parent eddbf0bc90
commit b8e1331a78
4 changed files with 6 additions and 2 deletions

View File

@ -25,6 +25,7 @@ database=database
appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cities=Caen|Paris|Saint-Lo cities=Caen|Paris|Saint-Lo
measurements=temp|humidity|pressure measurements=temp|humidity|pressure
units=metric
``` ```
### Run ### Run

View File

@ -20,6 +20,7 @@ func GetConfig(config *Config, configfile string) error {
weatherSection := cfg.Section("weather") weatherSection := cfg.Section("weather")
config.WeatherAppID = weatherSection.Key("appid").MustString("appid") config.WeatherAppID = weatherSection.Key("appid").MustString("appid")
config.WeatherUnits = weatherSection.Key("units").MustString("")
config.WeatherCities = weatherSection.Key("cities").Strings("|") config.WeatherCities = weatherSection.Key("cities").Strings("|")
if len(config.WeatherCities) < 1 { if len(config.WeatherCities) < 1 {
return fmt.Errorf("No cities provided in config") return fmt.Errorf("No cities provided in config")
@ -33,7 +34,7 @@ func GetConfig(config *Config, configfile string) error {
config.InfluxURL = influxdbSection.Key("url").MustString("http://localhost:8086") config.InfluxURL = influxdbSection.Key("url").MustString("http://localhost:8086")
config.InfluxUser = influxdbSection.Key("username").MustString("username") config.InfluxUser = influxdbSection.Key("username").MustString("username")
config.InfluxPass = influxdbSection.Key("password").MustString("password") config.InfluxPass = influxdbSection.Key("password").MustString("password")
config.InfluxDB = influxdbSection.Key("database").MustString("me") config.InfluxDB = influxdbSection.Key("database").MustString("database")
return err return err
} }
@ -41,6 +42,7 @@ func GetConfig(config *Config, configfile string) error {
// Config is the main configuration // Config is the main configuration
type Config struct { type Config struct {
WeatherAppID string WeatherAppID string
WeatherUnits string
WeatherCities []string WeatherCities []string
WeatherMeasurements []string WeatherMeasurements []string
InfluxURL string InfluxURL string

View File

@ -22,7 +22,7 @@ func FetchData(c *config.Config, city string) (Data, error) {
DisableCompression: false, DisableCompression: false,
}} }}
q := fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=metric", city, c.WeatherAppID) q := fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=%s", city, c.WeatherAppID, c.WeatherUnits)
r, err := httpClient.Get(q) r, err := httpClient.Get(q)
if err != nil { if err != nil {

View File

@ -8,3 +8,4 @@ database=database
appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cities=Caen|Paris|Saint-Lo cities=Caen|Paris|Saint-Lo
measurements=temp|humidity|pressure measurements=temp|humidity|pressure
units=metric