diff options
| author | Petri Hienonen <petri.hienonen@gmail.com> | 2026-02-01 22:15:14 +0200 |
|---|---|---|
| committer | Petri Hienonen <petri.hienonen@gmail.com> | 2026-02-01 22:15:14 +0200 |
| commit | 50541ca317e2ae647fc83d25e38825bb5a120296 (patch) | |
| tree | 16bb87964a1809a83bb69db8ac69e12f457862b5 /converter.go | |
| parent | b99d904cd2b37feb129a6d747d1ce422d31cffba (diff) | |
| download | weather-50541ca317e2ae647fc83d25e38825bb5a120296.tar.zst | |
Add initial TUI
Diffstat (limited to 'converter.go')
| -rw-r--r-- | converter.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/converter.go b/converter.go index 0e2b74c..fa49a61 100644 --- a/converter.go +++ b/converter.go @@ -1,4 +1,4 @@ -// converter.go - Converts ForecastData to OWMResponse +// converter.go - Update to use exported FmiToOwm map package main import ( @@ -119,7 +119,27 @@ func (fd *ForecastData) convertToCurrent(index int, timestamp int64, loc *time.L if val, err := fd.getFloatValue(index, "WeatherSymbol3"); err == nil && !math.IsNaN(val) { symbol := int(math.Round(val)) forecastTime := time.Unix(timestamp, 0) - current.Weather = []Weather{mapper.Map(symbol, forecastTime, sunrise, sunset)} + + // Use the mapper or fallback to the global map + var weather Weather + if mapper != nil { + weather = mapper.Map(symbol, forecastTime, sunrise, sunset) + } else { + // Fallback to global map + if w, ok := FmiToOwm[symbol]; ok { + weather = w + // Determine day/night + isDay := forecastTime.After(sunrise) && forecastTime.Before(sunset) + if isDay { + weather.Icon += "d" + } else { + weather.Icon += "n" + } + } else { + weather = Weather{800, "Clear", "clear sky", "01d"} + } + } + current.Weather = []Weather{weather} } else { // Default weather current.Weather = []Weather{{800, "Clear", "clear sky", "01d"}} |
