diff --git a/weatherservices/weather/display.go b/weatherservices/weather/display.go index 9eef59b2..0648b45c 100644 --- a/weatherservices/weather/display.go +++ b/weatherservices/weather/display.go @@ -72,5 +72,5 @@ func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string { } func (widget *Widget) title(cityData *owm.CurrentWeatherData) string { - return fmt.Sprintf(" %s %s ", widget.icon(cityData), cityData.Name) + return fmt.Sprintf(" %s %s ", widget.emojiFor(cityData), cityData.Name) } diff --git a/weatherservices/weather/emoji.go b/weatherservices/weather/emoji.go new file mode 100644 index 00000000..15dafe82 --- /dev/null +++ b/weatherservices/weather/emoji.go @@ -0,0 +1,47 @@ +package weather + +import ( + owm "github.com/briandowns/openweathermap" +) + +var weatherEmoji = map[string]string{ + "default": "💥", + "broken clouds": "~", + "clear": " ", + "clear sky": " ", + "cloudy": "⛅️", + "few clouds": "🌤", + "fog": "🌫", + "haze": "🌫", + "heavy intensity rain": "💦", + "heavy rain": "💦", + "heavy snow": "⛄️", + "light intensity shower rain": "☔️", + "light rain": "🌦", + "light shower snow": "🌦⛄️", + "light snow": "🌨", + "mist": "🌬", + "moderate rain": "🌧", + "moderate snow": "🌨", + "overcast": "🌥", + "overcast clouds": "🌥", + "partly cloudy": "🌤", + "scattered clouds": "🌤", + "shower rain": "☔️", + "snow": "❄️", + "sunny": "☀️", + "thunderstorm": "⛈", +} + +func (widget *Widget) emojiFor(data *owm.CurrentWeatherData) string { + if len(data.Weather) == 0 { + return "" + } + + emoji := weatherEmoji[data.Weather[0].Description] + if emoji == "" { + emoji = weatherEmoji["default"] + } + + return emoji +} diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index 6416f0a2..f58d7bed 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -163,76 +163,6 @@ func (widget *Widget) defaultCityCodes() []interface{} { return defaults } -// icon returns an emoji for the current weather -// src: https://github.com/chubin/wttr.in/blob/master/share/translations/en.txt -// Note: these only work for English weather status. Sorry about that -// -// FIXME: Move these into a configuration file so they can be changed without a compile -func (widget *Widget) icon(data *owm.CurrentWeatherData) string { - var icon string - - if len(data.Weather) == 0 { - return "" - } - - switch data.Weather[0].Description { - case "broken clouds": - icon = "☁️" - case "clear": - icon = "☀️" - case "clear sky": - icon = "☀️" - case "cloudy": - icon = "⛅️" - case "few clouds": - icon = "🌤" - case "fog": - icon = "🌫" - case "haze": - icon = "🌫" - case "heavy intensity rain": - icon = "💦" - case "heavy rain": - icon = "💦" - case "heavy snow": - icon = "⛄️" - case "light intensity shower rain": - icon = "☔️" - case "light rain": - icon = "🌦" - case "light shower snow": - icon = "🌦⛄️" - case "light snow": - icon = "🌨" - case "mist": - icon = "🌬" - case "moderate rain": - icon = "🌧" - case "moderate snow": - icon = "🌨" - case "overcast": - icon = "🌥" - case "overcast clouds": - icon = "🌥" - case "partly cloudy": - icon = "🌤" - case "scattered clouds": - icon = "☁️" - case "shower rain": - icon = "☔️" - case "snow": - icon = "❄️" - case "sunny": - icon = "☀️" - case "thunderstorm": - icon = "⛈" - default: - icon = "💥" - } - - return icon -} - func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { switch string(event.Rune()) { case "/":