-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsdeck.go
More file actions
37 lines (32 loc) · 767 Bytes
/
wsdeck.go
File metadata and controls
37 lines (32 loc) · 767 Bytes
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
package main
import (
"fmt"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
func getCardDeckInfo(url string) ([]Card, error) {
var cardsDeck = []Card{}
doc, err := goquery.NewDocument(url)
if err != nil {
fmt.Println(err)
return cardsDeck, err
}
doc.Find("div .wscard").Each(func(i int, s *goquery.Selection) {
card := Card{}
cardID, exists := s.Attr("data-cardid")
if exists {
var split = strings.Split(cardID, "-")
card.ID = fmt.Sprintf("%s%s%s", split[0], "-", strings.Replace(split[1], "E", "", 1))
}
cardAmount, exists := s.Attr("data-amount")
if exists {
card.Amount, err = strconv.Atoi(cardAmount)
if err != nil {
fmt.Println(err)
}
}
cardsDeck = append(cardsDeck, card)
})
return cardsDeck, nil
}