-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (39 loc) · 924 Bytes
/
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
package main
import (
"fmt"
"os"
"net/http"
"io/ioutil"
"strings"
"github.com/urfave/cli"
)
func main(){
var rate string
app := cli.NewApp()
app.Name = "sameura"
app.Usage = "get Sameura Dam status"
app.Action = func(c *cli.Context) error {
domain := "http://www1.river.go.jp"
resp, _ := http.Get(domain + "/cgi-bin/DspDamData.exe?ID=1368080700010&KIND=3")
defer resp.Body.Close()
b1, _ := ioutil.ReadAll(resp.Body)
b2 := GetObsPage(domain, string(b1))
tr := "<TR>"
trs := strings.Split(b2, tr)
for i := 1; i < len(trs); i++ {
td := "</TD>"
tds := strings.Split(trs[i], td)
tag := ">"
rates := strings.Split(tds[len(tds)-2], tag)
if string(rates[1]) != "-" {
rate = rates[2]
break
}
}
un := "<"
value := strings.Split(rate, un)
fmt.Printf("早明浦ダムの現在の貯水率は %s %%です.\n", string(value[0]))
return nil
}
app.Run(os.Args)
}