summaryrefslogtreecommitdiff
path: root/weather.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-06 22:32:44 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-06 22:32:44 +0200
commit4db4bdb5343b184e0d905670219e9bdfbfafb726 (patch)
tree795d37eccfcca6dc4caeb29c6fffc478524edee0 /weather.go
Initial import
Diffstat (limited to 'weather.go')
-rw-r--r--weather.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/weather.go b/weather.go
new file mode 100644
index 0000000..ed4a139
--- /dev/null
+++ b/weather.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "io/ioutil"
+ "net/http"
+ "strings"
+ "errors"
+)
+
+const (
+ noaa = `http://weather.noaa.gov/pub/data/observations/metar/`
+ noaaDecoded = noaa + `decoded/`
+ noaaStations = noaa + `stations/`
+)
+
+var notFound = errors.New("not found")
+
+func FetchMetar(s string) ([]string, error) {
+ loc := noaaStations + strings.ToUpper(s[:4]) + ".TXT"
+ resp, err := http.Get(loc)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode == http.StatusNotFound {
+ return nil, notFound
+ }
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+ return strings.Split(strings.TrimSpace(string(body)), "\n"), nil
+}