-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.29 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
package main
import "fmt"
import "time"
import "html/template"
import "net/http"
import "github.com/fjukstad/headwind/yr"
func main() {
tmpl := template.Must(template.ParseFiles("index.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fc, err := yr.GetForecast(0, 0)
if err != nil {
fmt.Println("Could not get forecast", err)
}
// bearing = 142.525
t := time.Now()
fmtTime := t.Format("2006-01-02 15:04:05")
fmt.Printf("%s %s %s %s\n", fmtTime, r.RemoteAddr, r.Method, r.URL)
direction := fc.Properties.TimeSeries[0].Data.Instant.Details.WindFromDirection
speed := fc.Properties.TimeSeries[0].Data.Instant.Details.WindSpeed
// bearing := 142.5
// to work
// super fancy headwind or not calculator 💩
headwind := false
if direction < 90 || direction > 200 {
headwind = true
}
description := ""
if speed < 4 {
description = "lett motvind"
} else if speed < 8 {
description = "grei motvind"
} else if speed < 15 {
description = "sterk motvind"
} else {
description = "kjør bil"
}
data := WindInfo{
Headwind: headwind,
Description: description,
Speed: speed,
}
tmpl.Execute(w, data)
})
http.ListenAndServe(":80", nil)
}
type WindInfo struct {
Headwind bool
Description string
Speed float64
}