diff options
Diffstat (limited to 'weather.go')
-rw-r--r-- | weather.go | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -133,7 +133,7 @@ type Weather struct { } var ( - bbc = flag.Bool("b", true, "use bbc as data source") + src = flag.String("s", "bbc", "data source provider (valid options: 'bbc', 'metoffice')") numdays = flag.Int("n", 2, "number of days to show") verbose = flag.Bool("v", false, "verbose: show all weather details") ) @@ -203,25 +203,28 @@ func processMet(b []byte) []Weather { func main() { var err error var id string + var url string var resp *http.Response var weather []Weather flag.Parse() + + switch *src { + case "bbc": + id = bbcdefid + url = bbcurl + case "metoffice": + id = metdefid + url = meturl + default: + log.Fatalf("data source %s not supported; use either 'bbc' or 'metoffice'\n", *src) + } + if flag.NArg() > 0 { id = flag.Arg(0) - } else { - if *bbc { - id = bbcdefid - } else { - id = metdefid - } } - if *bbc { - resp, err = http.Get(fmt.Sprintf(bbcurl, id)) - } else { - resp, err = http.Get(fmt.Sprintf(meturl, id)) - } + resp, err = http.Get(fmt.Sprintf(url, id)) if err != nil { log.Fatal(err) } @@ -231,7 +234,7 @@ func main() { } b, err := ioutil.ReadAll(resp.Body) - if *bbc { + if *src == "bbc" { weather = processBBC(b) } else { weather = processMet(b) |