summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2018-03-21 18:59:41 +0000
committerNick White <git@njw.name>2018-03-21 18:59:41 +0000
commit04f2a8404a49b1d55e2e94718657280879cf04a9 (patch)
treeda0accbcfadced8008c96e0289b86a10dcd5b8a8
parentc8053d860c703736f98bd17a1aec154e04364cfa (diff)
downloadweather-04f2a8404a49b1d55e2e94718657280879cf04a9.tar.bz2
weather-04f2a8404a49b1d55e2e94718657280879cf04a9.zip
Add structs for expected json to unmarshall into. Still need to switch to actually using them
-rw-r--r--weather.go58
1 files changed, 47 insertions, 11 deletions
diff --git a/weather.go b/weather.go
index 7ca592e..b81cc9f 100644
--- a/weather.go
+++ b/weather.go
@@ -2,6 +2,8 @@ package main
// TODO: allow free-text lookups of place names, rather than ids
// TODO: decode weather type number
+// TODO: split out met office specific stuff to separate module
+// TODO: add other weather providers
import (
"encoding/json"
@@ -16,20 +18,54 @@ import (
const defid = "310118"
var wkey = map[string]string{
- "f": "Feels Like Temperature",
- "h": "Humidity",
- "p": "Pressure",
- "t": "Temperature",
- "v": "Visibility",
- "wg": "Wind Gust",
- "ws": "Wind Speed",
- "pp": "Precipitaton Probability",
- "uv": "Max UV Index",
- "wd": "Wind Direction",
- "wt": "Weather Type",
+ "f": "Feels Like Temperature",
+ "h": "Humidity",
+ "p": "Pressure",
+ "t": "Temperature",
+ "v": "Visibility",
+ "wg": "Wind Gust",
+ "ws": "Wind Speed",
+ "pp": "Precipitaton Probability",
+ "uv": "Max UV Index",
+ "wd": "Wind Direction",
+ "wt": "Weather Type",
"AQIndex": "Air Quality",
}
+type Response struct {
+ BestFcst struct {
+ Location struct {
+ Days []Day `json:"Day"`
+ }
+ }
+}
+
+type Day struct {
+ DayValues WeatherParam
+ NightValues WeatherParam
+ TimeSteps struct {
+ TimeStep struct {
+ Time string `json:"@time"`
+ WeatherParams []WeatherParam
+ }
+ }
+}
+
+type WeatherParam struct {
+ AQIndex float64
+ F float64
+ H float64
+ P float64
+ PP float64
+ UV float64
+ T float64
+ V float64
+ WD string
+ WG float64
+ WS float64
+ WT float64
+}
+
func main() {
var j map[string]interface{}
var id string