From e346933cf5f3e2a652e89f3a3467c569b0330291 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 5 Feb 2021 14:14:22 +0000 Subject: Convert windspeed from metoffice to mph --- weather.go | 12 +++++------- 1 file 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) } } -- cgit v1.2.3