-
Notifications
You must be signed in to change notification settings - Fork 0
/
jp_fetcher.go
45 lines (35 loc) · 1021 Bytes
/
jp_fetcher.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
package jp
import (
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/shionit/kabuka/internal/app/kabuka/fetcher"
"github.com/shionit/kabuka/internal/app/kabuka/model"
)
const (
selectorCurrentPrice = "#root > main > div > div > div.XuqDlHPN div section._1zZriTjI._2l2sDX5w > div._1nb3c4wQ > header > div.nOmR5zWz > span > span > span"
)
var (
supportMarketNamesPrefix = [...]string{"東証", "名証", "札幌", "福岡"}
)
func init() {
fetcher.RegisterFetcher(&jpFetcher{})
}
type jpFetcher struct {
fetcher.Fetcher
}
func (f *jpFetcher) IsMarket(doc *goquery.Document) bool {
marketName := fetcher.GetMarketName(doc)
for _, prefix := range supportMarketNamesPrefix {
if strings.HasPrefix(marketName, prefix) {
return true
}
}
return false
}
func (f *jpFetcher) Fetch(doc *goquery.Document, symbol string) (*model.Stock, error) {
curPrice := doc.Find(selectorCurrentPrice).Text()
return &model.Stock{
Symbol: symbol,
CurrentPrice: fetcher.FormatPrice(curPrice),
}, nil
}