summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-02-05 15:42:18 +0000
committerNick White <git@njw.name>2021-02-05 15:42:18 +0000
commit50afc48fdc1e437102e574811a73c2367bc4e30d (patch)
treeeb2b61d6e5d84f38ae7b2fd49c81c7a367dbd223
parentfb840849c8ac587e3963feb41298314ab4efc90f (diff)
downloadweather-50afc48fdc1e437102e574811a73c2367bc4e30d.tar.bz2
weather-50afc48fdc1e437102e574811a73c2367bc4e30d.zip
Capture all data available so verbose mode is more useful
-rw-r--r--weather.go45
1 files changed, 41 insertions, 4 deletions
diff --git a/weather.go b/weather.go
index dad9f2d..996b3e4 100644
--- a/weather.go
+++ b/weather.go
@@ -139,11 +139,19 @@ var TypeDescription = map[int]string{
// Our prefered struct
type Weather struct {
+ airquality int
date string
- time string
- temperature float64
+ feelsliketemp float64
+ humidity int
+ maxuv int
precipitation int
+ pressure int
+ temperature float64
+ time string
+ visibility int
weathertype int
+ winddir string
+ windgust float64
windspeed float64
}
@@ -165,9 +173,15 @@ func processBBC(b []byte) []Weather {
for _, report := range f.Detailed.Reports {
w.date = report.LocalDate
w.time = report.Timeslot
+ w.feelsliketemp = float64(report.FeelsLikeTemperatureC)
+ w.humidity = report.Humidity
w.temperature = float64(report.TemperatureC)
w.precipitation = report.PrecipitationProbabilityInPercent
+ w.pressure = report.Pressure
+ w.visibility = estimateVisibility(report.Visibility)
w.weathertype = report.WeatherType
+ w.winddir = report.WindDirectionFull
+ w.windgust = float64(report.GustSpeedMph)
w.windspeed = float64(report.WindSpeedMph)
weather = append(weather, w)
}
@@ -175,12 +189,35 @@ func processBBC(b []byte) []Weather {
return weather
}
+// estimateVisibility returns a rough number of meters
+// of vilibility based on descriptive text.
+func estimateVisibility(s string) int {
+ switch s {
+ case "Good":
+ return 10000
+ case "Moderate":
+ return 5000
+ case "Poor":
+ return 500
+ default:
+ return 0
+ }
+}
+
func parseMetWeather(wp WeatherParams) Weather {
var w Weather
- w.temperature = wp.T
+ w.airquality = wp.AQIndex
+ w.feelsliketemp = wp.F
+ w.humidity = wp.H
+ w.pressure = wp.P
w.precipitation = wp.PP
+ w.temperature = wp.T
+ w.maxuv = wp.UV
+ w.visibility = wp.V
w.weathertype = wp.WT
+ w.winddir = wp.WD
+ w.windgust = wp.WG
w.windspeed = wp.WS * mpsToMphMultiplier
return w
@@ -268,7 +305,7 @@ func main() {
fmt.Printf("%18s, Temp: %4.1f°C, ", desc, w.temperature)
fmt.Printf("Rain: %2d%%, Wind: %4.1fmph\n", w.precipitation, w.windspeed)
if *verbose {
- fmt.Printf(" %+v\n", w)
+ fmt.Printf("%+v\n\n", w)
}
}
}