From 71b0500c6fefcac1da092ce54e35efb75e3d9e76 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 29 Mar 2018 02:52:02 -0700 Subject: [PATCH] A bit of intelligence around which weather emoji gets displayed --- weather/widget.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/weather/widget.go b/weather/widget.go index b4e469bc..86c10e39 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -1,10 +1,9 @@ package weather import ( - //"bytes" "fmt" - //"text/template" + owm "github.com/briandowns/openweathermap" "github.com/rivo/tview" ) @@ -14,7 +13,7 @@ func Widget() tview.Primitive { widget := tview.NewTextView() widget.SetBorder(true) widget.SetDynamicColors(true) - widget.SetTitle(fmt.Sprintf(" 🌤 Weather - %s ", data.Name)) + widget.SetTitle(fmt.Sprintf(" %s Weather - %s ", icon(data), data.Name)) str := fmt.Sprintf("\n") for _, weather := range data.Weather { @@ -31,6 +30,33 @@ func Widget() tview.Primitive { } // icon returns an emoji for the current weather -func icon() string { - return "" +func icon(data *owm.CurrentWeatherData) string { + var icon string + + switch data.Weather[0].Description { + case "clear": + icon = "☀️" + case "cloudy": + icon = "⛅️" + case "heavy rain": + icon = "🌧" + case "light rain": + icon = "🌧" + case "moderate rain": + icon = "🌧" + case "overcast": + icon = "🌥" + case "overcast clouds": + icon = "🌥" + case "partly cloudy": + icon = "🌤" + case "snow": + icon = "❄️" + case "sunny": + icon = "☀️" + default: + icon = "🌈" + } + + return icon }