-
Notifications
You must be signed in to change notification settings - Fork 0
/
wstcg.go
62 lines (53 loc) · 1.39 KB
/
wstcg.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
package main
import (
"fmt"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
type wstcg struct{}
func (e wstcg) getCardDeckInfo(url string) ([]Card, error) {
var cardsDeck = []Card{}
return cardsDeck, nil
}
func (e wstcg) name() string {
return "wstcg"
}
func (e wstcg) getCardDecksInfoList(url string) ([][]Card, error) {
var decks = [][]Card{}
doc, err := goquery.NewDocument(url)
if err != nil {
fmt.Println(err)
return decks, err
}
doc.Find("table.deckrecipe_table").Each(func(i int, s *goquery.Selection) {
cardsDeck := []Card{}
s.Find("tr").Each(func(i int, s *goquery.Selection) {
card := Card{}
cardID := s.Find(".cardno").Text()
if cardID != "" {
var split = strings.Split(cardID, "-")
card.ID = strings.ToUpper(fmt.Sprintf("%s%s%s", split[0], "-", strings.Replace(split[1], "E", "", 1)))
} else {
return
}
cardAmount := s.Find(".cardnum").Text()
if cardAmount != "" {
cardAmount = strings.TrimSpace(strings.TrimRight(cardAmount, "枚"))
// Japanese bullshit '4' != '4'
jpwhut := string(fmt.Sprintf("%+q", cardAmount))
r := string(jpwhut[len(jpwhut)-2])
card.Amount, err = strconv.Atoi(r)
if err != nil {
fmt.Println(err)
}
}
cardsDeck = append(cardsDeck, card)
})
decks = append(decks, cardsDeck)
})
return decks, nil
}
func (e wstcg) isMine(url string) bool {
return strings.Contains(url, "ws-tcg")
}