-
Notifications
You must be signed in to change notification settings - Fork 4
/
pvpteam.go
80 lines (65 loc) · 2.53 KB
/
pvpteam.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
package godestone
import (
"strconv"
"time"
"github.com/gocolly/colly/v2"
"github.com/xivapi/godestone/v2/data/gcrank"
)
func (s *Scraper) buildPVPTeamCollector(pvpTeam *PVPTeam) *colly.Collector {
c := colly.NewCollector(
colly.UserAgent(s.meta.UserAgentDesktop),
colly.IgnoreRobotsTxt(),
colly.Async(),
)
basicSelectors := s.getPVPTeamSelectors().Basic
c.OnHTML(basicSelectors.Name.Selector, func(e *colly.HTMLElement) {
pvpTeam.Name = basicSelectors.Name.Parse(e)[0]
})
c.OnHTML(basicSelectors.DC.Selector, func(e *colly.HTMLElement) {
pvpTeam.DC = basicSelectors.DC.Parse(e)[0]
})
c.OnHTML(basicSelectors.Formed.Selector, func(e *colly.HTMLElement) {
datetimeSecondsStr := basicSelectors.Formed.Parse(e)[0]
datetimeSeconds, err := strconv.ParseInt(datetimeSecondsStr, 10, 32)
if err == nil {
pvpTeam.Formed = time.Unix(0, datetimeSeconds*1000*int64(time.Millisecond))
}
})
pvpTeam.CrestLayers = &CrestLayers{}
c.OnHTML(basicSelectors.CrestLayers.Bottom.Selector, func(e *colly.HTMLElement) {
pvpTeam.CrestLayers.Bottom = basicSelectors.CrestLayers.Bottom.Parse(e)[0]
})
c.OnHTML(basicSelectors.CrestLayers.Middle.Selector, func(e *colly.HTMLElement) {
pvpTeam.CrestLayers.Middle = basicSelectors.CrestLayers.Middle.Parse(e)[0]
})
c.OnHTML(basicSelectors.CrestLayers.Top.Selector, func(e *colly.HTMLElement) {
pvpTeam.CrestLayers.Top = basicSelectors.CrestLayers.Top.Parse(e)[0]
})
pvpTeam.Members = []*PVPTeamMember{}
membersSelectors := s.getPVPTeamSelectors().Members
c.OnHTML(membersSelectors.Root.Selector, func(e1 *colly.HTMLElement) {
e1.ForEach(membersSelectors.Entry.Root.Selector, func(i int, e2 *colly.HTMLElement) {
member := &PVPTeamMember{
Avatar: membersSelectors.Entry.Avatar.ParseThroughChildren(e2)[0],
Name: membersSelectors.Entry.Name.ParseThroughChildren(e2)[0],
Rank: gcrank.Parse(membersSelectors.Entry.Rank.ParseThroughChildren(e2)[0]),
RankIcon: membersSelectors.Entry.RankIcon.ParseThroughChildren(e2)[0],
}
worldDC := membersSelectors.Entry.Server.ParseThroughChildren(e2)
member.World = worldDC[0]
member.DC = worldDC[1]
idStr := membersSelectors.Entry.ID.ParseThroughChildren(e2)[0]
id, err := strconv.ParseUint(idStr, 10, 32)
if err == nil {
member.ID = uint32(id)
}
matchesStr := membersSelectors.Entry.Matches.ParseThroughChildren(e2)[0]
matches, err := strconv.ParseUint(matchesStr, 10, 32)
if err == nil {
member.Matches = uint32(matches)
}
pvpTeam.Members = append(pvpTeam.Members, member)
})
})
return c
}