-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassdata.go
162 lines (130 loc) · 3.43 KB
/
passdata.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"fmt"
"strings"
)
type parkItem struct {
name string
leftCount string
allCount string
updateDate string
updateTime string
}
func getPadSpaceForName(length int) string {
max := 16
// chinese utf8 is 3
word := length / 3
var b []byte
// When showing chinese word, it only needs two bytes.
limit := max * 2 - word * 2
for i := 0; i < limit; i++ {
b = append(b, ' ')
}
return string(b)
}
func formatParkInfo(item *parkItem) string {
yi := strings.Index(item.updateDate, "年")
mi := strings.Index(item.updateDate, "月")
di := strings.Index(item.updateDate, "日")
hi := strings.Index(item.updateTime, "時")
mini := strings.Index(item.updateTime, "分")
si := strings.Index(item.updateTime, "秒")
var year, month, day, hour, min, sec string
if yi != -1 && mi != -1 && di != -1 &&
hi != -1 && mini != -1 && si != -1 {
year = item.updateDate[:yi]
month = item.updateDate[yi+len("年"):mi]
day = item.updateDate[mi+len("月"):di]
hour = item.updateTime[:hi]
min = item.updateTime[hi+len("時"):mini]
sec = item.updateTime[mini+len("分"):si]
}
space := getPadSpaceForName(len(item.name))
return fmt.Sprintf(
"%s%s %-4s %-4s %s/%s/%s %s:%s:%s",
item.name, space, item.leftCount, item.allCount,
year, month, day, hour, min, sec,
)
}
//-----------------------------------------------------------------------------
/*
--- 2018/5/31 format
--- 有顏色的才會有 span tag
<tr>
<td class='Point' width='18%'>新店安坑停車場(岳洋)</td>
<td class='Text_Center' width='22%'>新北市新店區安康路2段341巷旁</td>
<td class='Text_Center' width='13%'>
<span style='color:red;'>3002</span>
</td>
<td class='Text_Center' width='11%'>42</td>
<td class='Text_Center' width='11%'>107年05月30日</td>
<td class='Text_Center' width='19%'>18時54分01秒</td>
</tr>
*/
func findParkInfo(s string, name string) string {
var item parkItem
item.name = name
c := ""
i := strings.Index(s, name)
if i == -1 {
return c
}
// "name"xxxxxxxx
ns := s[i:]
// move to leftCount. it maybe has "span tag" or not.
count := 0
for {
i = strings.Index(ns, ">")
if i == -1 {
return c
}
ns = ns[i+1:]
count++
if count == 4 {
i = 0
break
}
}
// if it has "span tag", move to the first byte of leftCount.
j := strings.Index(ns, "<span")
if j == 0 {
i = strings.Index(ns, ">")
if i == -1 {
return c
}
ns = ns[i+1:]
i = 0
}
// find the boundary of LeftCount
i1 := strings.Index(ns, "<")
if i1 == -1 {
return c
}
item.leftCount = ns[i:i1]
ns = ns[i1+1:]
var msg [3]string
count = 0
for {
// "td tag" begin
i := strings.Index(ns, "'>")
if i == -1{
return c
}
ns = ns[i+2:]
// "td tag" end(</td>)
i1 := strings.Index(ns, "<")
if i1 == -1 {
return c
}
msg[count] = ns[:i1]
count++
ns = ns[i1+1:]
if count == 3 {
break
}
}
item.allCount = msg[0]
item.updateDate = msg[1]
item.updateTime = msg[2]
return formatParkInfo(&item)
}