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"
|
secretFile: "~/.wtf/gcal/client_secret.json"
|
||||||
git:
|
git:
|
||||||
commitCount: 5
|
commitCount: 5
|
||||||
enabled: true
|
enabled: false
|
||||||
position:
|
position:
|
||||||
top: 0
|
top: 0
|
||||||
left: 2
|
left: 2
|
||||||
@ -51,7 +51,7 @@ wtf:
|
|||||||
refreshInterval: 900
|
refreshInterval: 900
|
||||||
newrelic:
|
newrelic:
|
||||||
applicationId: 10549735
|
applicationId: 10549735
|
||||||
enabled: true
|
enabled: false
|
||||||
deployCount: 7
|
deployCount: 7
|
||||||
position:
|
position:
|
||||||
top: 4
|
top: 4
|
||||||
@ -68,7 +68,7 @@ wtf:
|
|||||||
width: 1
|
width: 1
|
||||||
refreshInterval: 21600
|
refreshInterval: 21600
|
||||||
security:
|
security:
|
||||||
enabled: true
|
enabled: false
|
||||||
position:
|
position:
|
||||||
top: 5
|
top: 5
|
||||||
left: 0
|
left: 0
|
||||||
@ -76,7 +76,7 @@ wtf:
|
|||||||
width: 1
|
width: 1
|
||||||
refreshInterval: 3600
|
refreshInterval: 3600
|
||||||
status:
|
status:
|
||||||
enabled: true
|
enabled: false
|
||||||
position:
|
position:
|
||||||
top: 5
|
top: 5
|
||||||
left: 2
|
left: 2
|
||||||
@ -85,7 +85,7 @@ wtf:
|
|||||||
refreshInterval: 1
|
refreshInterval: 1
|
||||||
weather:
|
weather:
|
||||||
cityId: 6173331
|
cityId: 6173331
|
||||||
enabled: false
|
enabled: true
|
||||||
language: "EN"
|
language: "EN"
|
||||||
position:
|
position:
|
||||||
top: 0
|
top: 0
|
||||||
|
@ -11,18 +11,20 @@ import (
|
|||||||
|
|
||||||
func Fetch(cityID int) *owm.CurrentWeatherData {
|
func Fetch(cityID int) *owm.CurrentWeatherData {
|
||||||
apiKey := os.Getenv("WTF_OWM_API_KEY")
|
apiKey := os.Getenv("WTF_OWM_API_KEY")
|
||||||
return currentWeather(apiKey, cityID)
|
data, _ := currentWeather(apiKey, cityID)
|
||||||
|
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- 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)
|
weather, err := owm.NewCurrent(Config.UString("wtf.weather.tempUnit", "C"), Config.UString("wtf.weather.language", "EN"), apiKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
weather.CurrentByID(cityCode)
|
weather.CurrentByID(cityCode)
|
||||||
|
|
||||||
return weather
|
return weather, nil
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,10 @@ func (widget *Widget) addView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
||||||
|
if len(data.Weather) == 0 {
|
||||||
|
return " Weather data is unavailable."
|
||||||
|
}
|
||||||
|
|
||||||
str := "\n"
|
str := "\n"
|
||||||
|
|
||||||
descs := []string{}
|
descs := []string{}
|
||||||
@ -90,6 +94,10 @@ func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
|||||||
func icon(data *owm.CurrentWeatherData) string {
|
func icon(data *owm.CurrentWeatherData) string {
|
||||||
var icon string
|
var icon string
|
||||||
|
|
||||||
|
if len(data.Weather) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
switch data.Weather[0].Description {
|
switch data.Weather[0].Description {
|
||||||
case "broken clouds":
|
case "broken clouds":
|
||||||
icon = "☁️"
|
icon = "☁️"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user