summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2018-03-22 16:23:43 +0000
committerNick White <git@njw.name>2018-03-22 16:23:43 +0000
commite2b29a75f139e163872dee499626596c754fc566 (patch)
treeb769192f277d8f48d8f1aed70bf8346b9b0729bd
parentdb58b6f12ee3bd80868b4edef43dd5fad08718f2 (diff)
downloadweather-e2b29a75f139e163872dee499626596c754fc566.tar.bz2
weather-e2b29a75f139e163872dee499626596c754fc566.zip
Add -n flag, and slightly improve output
-rw-r--r--weather.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/weather.go b/weather.go
index 1c51a80..d55297b 100644
--- a/weather.go
+++ b/weather.go
@@ -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)