summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-02-05 14:14:22 +0000
committerNick White <git@njw.name>2021-02-05 14:14:22 +0000
commite346933cf5f3e2a652e89f3a3467c569b0330291 (patch)
tree93444a5b04f0c988f8cf73ee36077a035a7fec17
parente17745805618d64026f254bbf9657e0e0a2b095e (diff)
downloadweather-e346933cf5f3e2a652e89f3a3467c569b0330291.tar.bz2
weather-e346933cf5f3e2a652e89f3a3467c569b0330291.zip
Convert windspeed from metoffice to mph
-rw-r--r--weather.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/weather.go b/weather.go
index ae0e90d..1510e60 100644
--- a/weather.go
+++ b/weather.go
@@ -1,10 +1,6 @@
package main
// TODO: allow free-text lookups of place names, rather than ids
-// TODO: convert metoffice windspeed to mph
-// TODO: split output into days
-// TODO: add -n flag to only output a certain number of days
-// TODO: human friendly dates
import (
"encoding/json"
@@ -21,6 +17,8 @@ const bbcdefid = "2654675"
const meturl = "https://www.metoffice.gov.uk/public/data/PWSCache/BestForecast/Forecast/%s.json?concise=true"
const bbcurl = "https://weather-broker-cdn.api.bbci.co.uk/en/forecast/aggregated/%s"
+const mpsToMphMultiplier = 2.23693629
+
// BBC structures
type BBCResponse struct {
Forecasts []struct {
@@ -187,7 +185,7 @@ func processMet(b []byte) []Weather {
w.temperature = d.DayValues.WeatherParameters.T
w.precipitation = d.DayValues.WeatherParameters.PP
w.weathertype = d.DayValues.WeatherParameters.WT
- w.windspeed = d.DayValues.WeatherParameters.WS
+ w.windspeed = d.DayValues.WeatherParameters.WS * mpsToMphMultiplier
weather = append(weather, w)
w.date = d.Date
@@ -195,7 +193,7 @@ func processMet(b []byte) []Weather {
w.temperature = d.DayValues.WeatherParameters.T
w.precipitation = d.DayValues.WeatherParameters.PP
w.weathertype = d.DayValues.WeatherParameters.WT
- w.windspeed = d.DayValues.WeatherParameters.WS
+ w.windspeed = d.DayValues.WeatherParameters.WS * mpsToMphMultiplier
weather = append(weather, w)
for _, t := range d.TimeSteps.TimeStep {
@@ -204,7 +202,7 @@ func processMet(b []byte) []Weather {
w.temperature = t.WeatherParameters.T
w.precipitation = t.WeatherParameters.PP
w.weathertype = t.WeatherParameters.WT
- w.windspeed = t.WeatherParameters.WS
+ w.windspeed = t.WeatherParameters.WS * mpsToMphMultiplier
weather = append(weather, w)
}
}