A self-hosted dashboard that puts all your feeds in one place
Go aggregatordashboarddockerfeed-readergohomelabhomepagemonitoringredditrssrss-readerself-hostedstartpageyoutube
Allow changing between C and F for weather temp
Svilen Markovccdafcdfab51
diff --git a/docs/configuration.md b/docs/configuration.mdindex 0fc76df..9c3bc13 100644--- a/docs/configuration.md+++ b/docs/configuration.md@@ -502,6 +502,7 @@ Example:```yaml- type: weather+ units: metriclocation: London, United Kingdom```@@ -516,11 +517,15 @@ Each bar represents a 2 hour interval. The yellow background represents sunrise| Name | Type | Required | Default || ---- | ---- | -------- | ------- || location | string | yes | |+| units | string | no | metric || hide-location | boolean | no | false |##### `location`The name of the city and country to fetch weather information for. Attempting to launch the applcation with an invalid location will result in an error. You can use the [gecoding API page](https://open-meteo.com/en/docs/geocoding-api) to search for your specific location. Glance will use the first result from the list if there are multiple.+##### `units`+Whether to show the temperature in celsius or fahrenheit, possible values are `metric` or `imperial`.+##### `hide-location`Optionally don't display the location name on the widget.diff --git a/internal/assets/templates/weather.html b/internal/assets/templates/weather.htmlindex 1cccdc0..b251186 100644--- a/internal/assets/templates/weather.html+++ b/internal/assets/templates/weather.html@@ -2,7 +2,7 @@{{ define "widget-content" }}<div class="size-h2 color-highlight text-center">{{ .Weather.WeatherCodeAsString }}</div>-<div class="size-h4 text-center">Feels like {{ .Weather.ApparentTemperature }}°C</div>+<div class="size-h4 text-center">Feels like {{ .Weather.ApparentTemperature }}°{{ if eq .Units "metric" }}C{{ else }}F{{ end }}</div><div class="weather-columns flex margin-top-15 justify-center">{{ range $i, $column := .Weather.Columns }}diff --git a/internal/feed/openmeteo.go b/internal/feed/openmeteo.goindex 604ac05..71438f0 100644--- a/internal/feed/openmeteo.go+++ b/internal/feed/openmeteo.go@@ -79,9 +79,15 @@ func barIndexFromHour(h int) int {}// TODO: bunch of spaget, refactor-// TODO: allow changing between C and F-func FetchWeatherForPlace(place *PlaceJson) (*Weather, error) {+func FetchWeatherForPlace(place *PlaceJson, units string) (*Weather, error) {query := url.Values{}+ var temperatureUnit string++ if units == "imperial" {+ temperatureUnit = "fahrenheit"+ } else {+ temperatureUnit = "celsius"+ }query.Add("latitude", fmt.Sprintf("%f", place.Latitude))query.Add("longitude", fmt.Sprintf("%f", place.Longitude))@@ -91,6 +97,7 @@ func FetchWeatherForPlace(place *PlaceJson) (*Weather, error) {query.Add("current", "temperature_2m,apparent_temperature,weather_code,wind_speed_10m")query.Add("hourly", "temperature_2m,precipitation_probability")query.Add("daily", "sunrise,sunset")+ query.Add("temperature_unit", temperatureUnit)requestUrl := "https://api.open-meteo.com/v1/forecast?" + query.Encode()request, _ := http.NewRequest("GET", requestUrl, nil)diff --git a/internal/widget/weather.go b/internal/widget/weather.goindex 390f9d7..a59b9b9 100644--- a/internal/widget/weather.go+++ b/internal/widget/weather.go@@ -13,6 +13,7 @@ type Weather struct {widgetBase `yaml:",inline"`Location string `yaml:"location"`HideLocation bool `yaml:"hide-location"`+ Units string `yaml:"units"`Place *feed.PlaceJson `yaml:"-"`Weather *feed.Weather `yaml:"-"`TimeLabels [12]string `yaml:"-"`@@ -24,6 +25,12 @@ func (widget *Weather) Initialize() error {widget.withTitle("Weather").withCacheOnTheHour()widget.TimeLabels = timeLabels+ if widget.Units == "" {+ widget.Units = "metric"+ } else if widget.Units != "metric" && widget.Units != "imperial" {+ return fmt.Errorf("invalid units '%s' for weather, must be either metric or imperial", widget.Units)+ }+place, err := feed.FetchPlaceFromName(widget.Location)if err != nil {@@ -36,7 +43,7 @@ func (widget *Weather) Initialize() error {}func (widget *Weather) Update(ctx context.Context) {- weather, err := feed.FetchWeatherForPlace(widget.Place)+ weather, err := feed.FetchWeatherForPlace(widget.Place, widget.Units)if !widget.canContinueUpdateAfterHandlingErr(err) {return