main.go - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
main.go (2248B)
---
1 package main
2
3 import (
4 "encoding/xml"
5 "fmt"
6 "os"
7 "strings"
8 "unicode"
9 )
10
11 type Feed struct {
12 Weerstations []struct {
13 Stationcode string `xml:"stationcode"`
14 Stationnaam string `xml:"stationnaam"`
15 Lat string `xml:"lat"`
16 Lon string `xml:"lon"`
17 LatGraden string `xml:"latGraden"`
18 LonGraden string `xml:"lonGraden"`
19 Datum string `xml:"datum"`
20 Luchtvochtigheid string `xml:"luchtvochtigheid"`
21 TemperatuurGC string `xml:"temperatuurGC"`
22 WindsnelheidMS string `xml:"windsnelheidMS"`
23 WindsnelheidBF string `xml:"windsnelheidBF"`
24 WindrichtingGR string `xml:"windrichtingGR"`
25 Windrichting string `xml:"windrichting"`
26 Luchtdruk string `xml:"luchtdruk"`
27 Zichtmeters string `xml:"zichtmeters"`
28 WindstotenMS string `xml:"windstotenMS"`
29 RegenMMPU string `xml:"regenMMPU"`
30 Temperatuur10cm string `xml:"temperatuur10cm"`
31 Icoonactueel struct {
32 ID string `xml:"ID,attr"`
33 Naam string `xml:"zin,attr"`
34 Url string `xml:",chardata"`
35 } `xml:"icoonactueel"`
36 } `xml:"weergegevens>actueel_weer>weerstations>weerstation"`
37 }
38
39 func main() {
40 feed := Feed{}
41 dec := xml.NewDecoder(os.Stdin)
42 err := dec.Decode(&feed)
43 if err != nil {
44 panic(err)
45 }
46
47 rm := func(r rune) rune {
48 if r == '"' || unicode.IsControl(r) {
49 return -1
50 }
51 return r
52 }
53
54 // 6280 groningen
55 // 6279 hoogeveen
56 // 6260 de bilt (utrecht)
57 for _, w := range feed.Weerstations {
58 values := map[string]string{
59 "stationnaam": w.Stationnaam,
60 "luchtvochtigheid": w.Luchtvochtigheid,
61 "temperatuurgc": w.TemperatuurGC,
62 "windsnelheidms": w.WindsnelheidMS,
63 "windsnelheidbf": w.WindsnelheidBF,
64 "windrichtinggr": w.WindrichtingGR,
65 "windrichting": w.Windrichting,
66 "luchtdruk": w.Luchtdruk,
67 "zichtmeters": w.Zichtmeters,
68 "regenmmpu": w.RegenMMPU,
69 "temperatuur10cm": w.Temperatuur10cm,
70 "actueeltekst": w.Icoonactueel.Naam,
71 }
72 for k, v := range values {
73 k = strings.Map(rm, k)
74 v = strings.Map(rm, v)
75
76 if v == "" || v == "-" {
77 continue
78 }
79 fmt.Printf("\"%s\" %s \"%s\"\n", w.Stationnaam, k, v)
80 //fmt.Printf("\"%s\" %s \"%s\"\n", w.Stationcode, k, v)
81 }
82 }
83 }