Skip to content

Commit bd19991

Browse files
author
jucky154
committed
push code
1 parent dd069d9 commit bd19991

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed

infoEs.go

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
package main
2+
3+
import (
4+
_ "embed"
5+
"github.com/PuerkitoBio/goquery"
6+
"github.com/gonutz/w32"
7+
"github.com/sqweek/dialog"
8+
"github.com/tadvi/winc"
9+
"strconv"
10+
"strings"
11+
"time"
12+
"unsafe"
13+
)
14+
15+
var (
16+
JST [8]string
17+
okinawa [8]string
18+
yamakawa [8]string
19+
kokubunji [8]string
20+
wakkanai [8]string
21+
abort chan struct{}
22+
)
23+
24+
const winsize = "infoEswindow"
25+
26+
type EsView struct {
27+
list *winc.ListView
28+
}
29+
30+
var esview EsView
31+
32+
type EsItem struct {
33+
Place string
34+
Power string
35+
State string
36+
Last string
37+
}
38+
39+
func (item EsItem) Text() (text []string) {
40+
text = append(text, item.Place)
41+
text = append(text, item.Power)
42+
text = append(text, item.State)
43+
text = append(text, item.Last)
44+
return
45+
}
46+
47+
func (item EsItem) ImageIndex() int {
48+
return 0
49+
}
50+
51+
func Escheck(area [8]string) (string, string, string) {
52+
Es_power := "不明"
53+
Es_state := "不明"
54+
Late_jst := JST[0]
55+
for index := 7; index >= 0; index = index - 1 {
56+
Es_power_num, err := strconv.ParseFloat(strings.TrimSpace(area[index]), 64)
57+
if err == nil {
58+
Late_jst = JST[index]
59+
Es_power = area[index]
60+
Es_state = "静穏"
61+
if Es_power_num > 7 {
62+
Es_state = "Es"
63+
}
64+
if Es_power_num > 8 {
65+
Es_state = "強いEs"
66+
}
67+
if Es_power_num > 9 {
68+
Es_state = "非常に強いEs"
69+
}
70+
break
71+
}
72+
}
73+
return Es_power, Es_state, Late_jst
74+
}
75+
76+
func EsUpdate() {
77+
//listを消す
78+
esview.list.DeleteAllItems()
79+
80+
//情報を取得
81+
get_url_info, err := goquery.NewDocument("https://wdc.nict.go.jp/IONO/fxEs/latest-fxEs.html")
82+
if err != nil {
83+
DisplayToast(err.Error())
84+
}
85+
86+
//必要なところだけ切り出し
87+
result := get_url_info.Find("td")
88+
result.Each(func(index int, s *goquery.Selection) {
89+
if index > 9 && index%5 == 0 {
90+
JST[index/5-2] = s.Text()
91+
}
92+
if index > 9 && index%5 == 1 {
93+
okinawa[index/5-2] = s.Text()
94+
}
95+
if index > 9 && index%5 == 2 {
96+
yamakawa[index/5-2] = s.Text()
97+
}
98+
if index > 9 && index%5 == 3 {
99+
kokubunji[index/5-2] = s.Text()
100+
}
101+
if index > 9 && index%5 == 4 {
102+
wakkanai[index/5-2] = s.Text()
103+
}
104+
})
105+
106+
//表示
107+
power, state, jst := Escheck(okinawa)
108+
esview.list.AddItem(EsItem{
109+
Place: "恩納/沖縄",
110+
Power: power,
111+
State: state,
112+
Last: jst,
113+
})
114+
115+
power, state, jst = Escheck(yamakawa)
116+
esview.list.AddItem(EsItem{
117+
Place: "山川/鹿児島",
118+
Power: power,
119+
State: state,
120+
Last: jst,
121+
})
122+
123+
power, state, jst = Escheck(kokubunji)
124+
esview.list.AddItem(EsItem{
125+
Place: "国分寺/東京",
126+
Power: power,
127+
State: state,
128+
Last: jst,
129+
})
130+
131+
power, state, jst = Escheck(wakkanai)
132+
esview.list.AddItem(EsItem{
133+
Place: "稚内/北海道",
134+
Power: power,
135+
State: state,
136+
Last: jst,
137+
})
138+
}
139+
140+
var mainWindow *winc.Form
141+
142+
func wndOnClose(arg *winc.Event) {
143+
x, y := mainWindow.Pos()
144+
w, h := mainWindow.Size()
145+
SetINI(winsize, "x", strconv.Itoa(x))
146+
SetINI(winsize, "y", strconv.Itoa(y))
147+
SetINI(winsize, "w", strconv.Itoa(w))
148+
SetINI(winsize, "h", strconv.Itoa(h))
149+
abort <- struct{}{}
150+
mainWindow.Close()
151+
}
152+
153+
func makewindow() {
154+
// --- Make Window
155+
mainWindow = winc.NewForm(nil)
156+
x, _ := strconv.Atoi(GetINI(winsize, "x"))
157+
y, _ := strconv.Atoi(GetINI(winsize, "y"))
158+
w, _ := strconv.Atoi(GetINI(winsize, "w"))
159+
h, _ := strconv.Atoi(GetINI(winsize, "h"))
160+
if w <= 0 || h <= 0 {
161+
w = 520
162+
h = 140
163+
}
164+
mainWindow.SetSize(w, h)
165+
if x <= 0 || y <= 0 {
166+
mainWindow.Center()
167+
} else {
168+
mainWindow.SetPos(x, y)
169+
}
170+
mainWindow.SetText("Eスポ情報")
171+
172+
esview.list = winc.NewListView(mainWindow)
173+
esview.list.EnableEditLabels(false)
174+
esview.list.AddColumn("観測地点", 120)
175+
esview.list.AddColumn("計測値", 120)
176+
esview.list.AddColumn("状態", 120)
177+
esview.list.AddColumn("最終観測時刻", 140)
178+
dock := winc.NewSimpleDock(mainWindow)
179+
dock.Dock(esview.list, winc.Fill)
180+
181+
mainWindow.Show()
182+
mainWindow.OnClose().Bind(wndOnClose)
183+
}
184+
185+
func UpdateLoop() {
186+
ticker := time.NewTicker(15 * time.Minute)
187+
for {
188+
select {
189+
case <-ticker.C:
190+
EsUpdate()
191+
case <-abort:
192+
return
193+
}
194+
}
195+
}
196+
197+
func init() {
198+
OnLaunchEvent = onLaunchEvent
199+
OnWindowEvent = onWindowEvent
200+
}
201+
202+
func onLaunchEvent() {
203+
hMenu1 := w32.HMENU(GetUI("MainForm.MainMenu"))
204+
hMenu2 := w32.CreateMenu()
205+
w32.AppendMenu(hMenu1, w32.MF_POPUP, uintptr(hMenu2), "Es情報")
206+
w32.AppendMenu(hMenu2, w32.MF_STRING, 10001, "ウィンドウを開く")
207+
w32.AppendMenu(hMenu2, w32.MF_STRING, 10002, "利用方法")
208+
w32.DrawMenuBar(w32.HWND(GetUI("MainForm")))
209+
}
210+
211+
func onWindowEvent(ptr uintptr) {
212+
msg := (*w32.MSG)(unsafe.Pointer(ptr))
213+
if msg.Message == w32.WM_COMMAND {
214+
switch msg.WParam {
215+
case 10001:
216+
abort = make(chan struct{})
217+
makewindow()
218+
EsUpdate()
219+
go UpdateLoop()
220+
case 10002:
221+
dialog.Message("%s", "このシステムはNICTのサイトから情報を取得しています。\n15分毎に自動更新しています。").Title("利用方法").Info()
222+
}
223+
}
224+
}

0 commit comments

Comments
 (0)