mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Gracefully handle weather data outages
This commit is contained in:
parent
01aab4cc53
commit
204e3b4032
10
config.yml
10
config.yml
@ -22,7 +22,7 @@ wtf:
|
||||
secretFile: "~/.wtf/gcal/client_secret.json"
|
||||
git:
|
||||
commitCount: 5
|
||||
enabled: true
|
||||
enabled: false
|
||||
position:
|
||||
top: 0
|
||||
left: 2
|
||||
@ -51,7 +51,7 @@ wtf:
|
||||
refreshInterval: 900
|
||||
newrelic:
|
||||
applicationId: 10549735
|
||||
enabled: true
|
||||
enabled: false
|
||||
deployCount: 7
|
||||
position:
|
||||
top: 4
|
||||
@ -68,7 +68,7 @@ wtf:
|
||||
width: 1
|
||||
refreshInterval: 21600
|
||||
security:
|
||||
enabled: true
|
||||
enabled: false
|
||||
position:
|
||||
top: 5
|
||||
left: 0
|
||||
@ -76,7 +76,7 @@ wtf:
|
||||
width: 1
|
||||
refreshInterval: 3600
|
||||
status:
|
||||
enabled: true
|
||||
enabled: false
|
||||
position:
|
||||
top: 5
|
||||
left: 2
|
||||
@ -85,7 +85,7 @@ wtf:
|
||||
refreshInterval: 1
|
||||
weather:
|
||||
cityId: 6173331
|
||||
enabled: false
|
||||
enabled: true
|
||||
language: "EN"
|
||||
position:
|
||||
top: 0
|
||||
|
@ -11,18 +11,20 @@ import (
|
||||
|
||||
func Fetch(cityID int) *owm.CurrentWeatherData {
|
||||
apiKey := os.Getenv("WTF_OWM_API_KEY")
|
||||
return currentWeather(apiKey, cityID)
|
||||
data, _ := currentWeather(apiKey, cityID)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func currentWeather(apiKey string, cityCode int) *owm.CurrentWeatherData {
|
||||
func currentWeather(apiKey string, cityCode int) (*owm.CurrentWeatherData, error) {
|
||||
weather, err := owm.NewCurrent(Config.UString("wtf.weather.tempUnit", "C"), Config.UString("wtf.weather.language", "EN"), apiKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
weather.CurrentByID(cityCode)
|
||||
|
||||
return weather
|
||||
return weather, nil
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ func (widget *Widget) addView() {
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
||||
if len(data.Weather) == 0 {
|
||||
return " Weather data is unavailable."
|
||||
}
|
||||
|
||||
str := "\n"
|
||||
|
||||
descs := []string{}
|
||||
@ -90,6 +94,10 @@ func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
||||
func icon(data *owm.CurrentWeatherData) string {
|
||||
var icon string
|
||||
|
||||
if len(data.Weather) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch data.Weather[0].Description {
|
||||
case "broken clouds":
|
||||
icon = "☁️"
|
||||
|
Loading…
x
Reference in New Issue
Block a user