1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch 'master' into zendesk_module

This commit is contained in:
Chris Cummer 2018-07-26 12:35:56 -04:00 committed by GitHub
commit ea8148a172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 71 deletions

View File

@ -72,5 +72,5 @@ func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string {
} }
func (widget *Widget) title(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)
} }

View File

@ -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
}

View File

@ -163,76 +163,6 @@ func (widget *Widget) defaultCityCodes() []interface{} {
return defaults 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 { func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) { switch string(event.Rune()) {
case "/": case "/":