-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (56 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"buienalarm/location"
"fmt"
"os"
)
func printUsage() {
fmt.Fprintf(os.Stderr, "usage: %s [-24] <location>\n", os.Args[0])
os.Exit(1)
}
func main() {
if len(os.Args) < 2 {
printUsage()
}
var locstr string
fullDay := false
if len(os.Args) == 2 {
locstr = os.Args[1]
} else if len(os.Args) == 3 {
switch os.Args[1] {
case "-2":
fullDay = false
case "-24":
fullDay = true
default:
printUsage()
}
locstr = os.Args[2]
}
loc, err := location.Geocode(locstr)
if err != nil {
fmt.Fprintln(os.Stderr, "error during geocode, maybe unknown location?")
os.Exit(1)
}
info, err := func() ([]timepoint, error) {
if fullDay {
return fetchFullDay(loc.Lat, loc.Lng)
}
return fetchTwoHours(loc.Lat, loc.Lng)
}()
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't retrieve forecast data from Buienradar: %s\n", err)
os.Exit(1)
}
if len(info) == 0 {
fmt.Fprintln(os.Stderr, "Warning: Empty body received from Buienradar")
}
for _, point := range info {
fmt.Printf(
"%02d:%02d: %.1fmm/u\n",
point.Time.Hour(),
point.Time.Minute(),
point.Precipation,
)
}
}