diff options
author | Nick White <git@njw.name> | 2018-03-22 16:23:43 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2018-03-22 16:23:43 +0000 |
commit | e2b29a75f139e163872dee499626596c754fc566 (patch) | |
tree | b769192f277d8f48d8f1aed70bf8346b9b0729bd | |
parent | db58b6f12ee3bd80868b4edef43dd5fad08718f2 (diff) | |
download | weather-e2b29a75f139e163872dee499626596c754fc566.tar.bz2 weather-e2b29a75f139e163872dee499626596c754fc566.zip |
Add -n flag, and slightly improve output
-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) |