-
Notifications
You must be signed in to change notification settings - Fork 3
/
list.go
60 lines (56 loc) · 1.35 KB
/
list.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
package finland
import (
"fmt"
"strings"
"github.com/whitewater-guide/gorge/core"
)
const epsg3067 = "+proj=utm +zone=35 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
func (s *scriptFinland) fetchList(url string, gauges *core.Gauges) error {
var data stationsList
err := core.Client.GetAsJSON(url, &data, nil)
if err != nil {
return err
}
for _, st := range data.Value {
lon, lat, err := core.ToEPSG4326(st.X, st.Y, epsg3067)
if err != nil {
continue
}
var levelUnit, flowUnit, unit string
if st.SuureID == 2 {
flowUnit = "m3/s"
unit = "discharge"
} else if st.SuureID == 1 {
levelUnit = "cm"
unit = "level"
} else {
continue
}
url := ""
if len(st.Nro) == 7 {
url = fmt.Sprintf("https://wwwi2.ymparisto.fi/i2/%s/q%sy/wqfi.html", st.Nro[:2], st.Nro)
}
*gauges = append(*gauges, core.Gauge{
GaugeID: core.GaugeID{
Script: s.name,
Code: fmt.Sprintf("%d", st.PaikkaID),
},
Name: fmt.Sprintf("%s - %s - %s (%s)", st.KuntaNimi, st.Nimi, st.Nro, unit),
URL: url,
LevelUnit: levelUnit,
FlowUnit: flowUnit,
Location: &core.Location{
Latitude: core.TruncCoord(lat),
Longitude: core.TruncCoord(lon),
},
})
}
if data.Next != "" {
next := data.Next
if !strings.HasPrefix(next, "http") {
next = s.url + next
}
return s.fetchList(next, gauges)
}
return nil
}