summaryrefslogtreecommitdiff
path: root/weather.go
diff options
context:
space:
mode:
Diffstat (limited to 'weather.go')
-rw-r--r--weather.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/weather.go b/weather.go
index 4fd1c36..b0ca2da 100644
--- a/weather.go
+++ b/weather.go
@@ -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)