diff options
-rw-r--r-- | weather.go | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -5,7 +5,6 @@ package main // TODO: split out met office specific stuff to separate module // TODO: add other weather providers // TODO: add -v verbose flag to show all data -// TODO: add -n flag to return a certain number of days import ( "encoding/json" @@ -59,6 +58,8 @@ type WeatherParams struct { WT int // Weather Type } +var numdays = flag.Int("n", 2, "number of days to show") + func main() { var r Response var id string @@ -82,12 +83,16 @@ func main() { log.Fatal(err) } - for i := len(r.BestFcst.Forecast.Location.Days) - 1; i >= 0; i-- { - d := r.BestFcst.Forecast.Location.Days[i] - fmt.Printf("-----------------------------\n") + for i, d := range r.BestFcst.Forecast.Location.Days { + if *numdays > 0 && i >= *numdays { + break + } + if i > 0 { + fmt.Printf("---------------------------------------------------------\n") + } fmt.Printf("%s\n", d.Date) - prettyWeather(" Day ", d.DayValues.WeatherParameters) - prettyWeather(" Night ", d.NightValues.WeatherParameters) + prettyWeather(" Day", d.DayValues.WeatherParameters) + prettyWeather(" Night", d.NightValues.WeatherParameters) for _, t := range d.TimeSteps.TimeStep { prettyWeather(t.Time, t.WeatherParameters) |