@@ -19,29 +19,37 @@ type Highscore struct {
1919 Title string `json:"title,omitempty"` // Title column (when category: loyalty)
2020}
2121
22+ // Child of Highscore
23+ type HighscorePage struct {
24+ CurrentPage int `json:"current_page"` // Current page
25+ TotalPages int `json:"total_pages"` // Total page count
26+ TotalHighscores int `json:"total_records"` // Total highscore records
27+ }
28+
2229// Child of JSONData
2330type Highscores struct {
24- World string `json:"world"`
25- Category string `json:"category"`
26- Vocation string `json:"vocation"`
27- HighscoreAge int `json:"highscore_age"`
28- HighscoreList []Highscore `json:"highscore_list"`
31+ World string `json:"world"`
32+ Category string `json:"category"`
33+ Vocation string `json:"vocation"`
34+ HighscoreAge int `json:"highscore_age"`
35+ HighscoreList []Highscore `json:"highscore_list"`
36+ HighscorePage HighscorePage `json:"highscore_page"`
2937}
3038
31- //
3239// The base includes two levels: Highscores and Information
3340type HighscoresResponse struct {
3441 Highscores Highscores `json:"highscores"`
3542 Information Information `json:"information"`
3643}
3744
3845var (
39- HighscoresAgeRegex = regexp .MustCompile (`.*<div class="Text">Highscores.*Last Update: ([0-9]+) minutes ago.*` )
40- SevenColumnRegex = regexp .MustCompile (`<td>.*<\/td><td.*">(.*)<\/a><\/td><td.*>(.*)<\/td><td.*>(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>` )
41- SixColumnRegex = regexp .MustCompile (`<td>.*<\/td><td.*">(.*)<\/a><\/td><td.*">(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>` )
46+ HighscoresAgeRegex = regexp .MustCompile (`.*<div class="Text">Highscores.*Last Update: ([0-9]+) minutes ago.*` )
47+ HighscoresPageRegex = regexp .MustCompile (`.*<b>\» Pages:\ ?(.*)<\/b>.*<b>\» Results:\ ?([0-9,]+)<\/b>.*` )
48+ SevenColumnRegex = regexp .MustCompile (`<td>(.*)<\/td><td.*">(.*)<\/a><\/td><td.*>(.*)<\/td><td.*>(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>` )
49+ SixColumnRegex = regexp .MustCompile (`<td>(.*)<\/td><td.*">(.*)<\/a><\/td><td.*">(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>` )
4250)
4351
44- func TibiaHighscoresV3Impl (world string , category HighscoreCategory , vocationName string , BoxContentHTML string ) HighscoresResponse {
52+ func TibiaHighscoresV3Impl (world string , category HighscoreCategory , vocationName string , currentPage int , BoxContentHTML string ) HighscoresResponse {
4553 // Loading HTML data into ReaderHTML for goquery with NewReader
4654 ReaderHTML , err := goquery .NewDocumentFromReader (strings .NewReader (BoxContentHTML ))
4755 if err != nil {
@@ -50,18 +58,24 @@ func TibiaHighscoresV3Impl(world string, category HighscoreCategory, vocationNam
5058
5159 // Creating empty HighscoreData var
5260 var (
53- HighscoreData []Highscore
54- HighscoreDataVocation , HighscoreDataWorld , HighscoreDataTitle string
55- HighscoreDataRank , HighscoreDataLevel , HighscoreDataValue , HighscoreAge int
61+ HighscoreData []Highscore
62+ HighscoreDataVocation , HighscoreDataWorld , HighscoreDataTitle string
63+ HighscoreDataRank , HighscoreDataLevel , HighscoreDataValue , HighscoreAge , HighscoreTotalPages , HighscoreTotalHighscores int
5664 )
5765
5866 // getting age of data
5967 subma1 := HighscoresAgeRegex .FindAllStringSubmatch (string (BoxContentHTML ), 1 )
60-
6168 if len (subma1 ) > 0 {
6269 HighscoreAge = TibiaDataStringToIntegerV3 (subma1 [0 ][1 ])
6370 }
6471
72+ // getting amount of pages
73+ subma1 = HighscoresPageRegex .FindAllStringSubmatch (string (BoxContentHTML ), 1 )
74+ if len (subma1 ) > 0 {
75+ HighscoreTotalPages = strings .Count (subma1 [0 ][1 ], "class=\" PageLink" )
76+ HighscoreTotalHighscores = TibiaDataStringToIntegerV3 (subma1 [0 ][2 ])
77+ }
78+
6579 // Running query over each div
6680 ReaderHTML .Find (".TableContent tr" ).First ().NextAll ().Each (func (index int , s * goquery.Selection ) {
6781
@@ -101,23 +115,23 @@ func TibiaHighscoresV3Impl(world string, category HighscoreCategory, vocationNam
101115
102116 if len (subma1 ) > 0 {
103117
104- HighscoreDataRank ++
118+ HighscoreDataRank = TibiaDataStringToIntegerV3 ( subma1 [ 0 ][ 1 ])
105119 if category == loyaltypoints {
106- HighscoreDataTitle = subma1 [0 ][2 ]
120+ HighscoreDataTitle = subma1 [0 ][3 ]
121+ HighscoreDataVocation = subma1 [0 ][4 ]
122+ HighscoreDataWorld = subma1 [0 ][5 ]
123+ HighscoreDataLevel = TibiaDataStringToIntegerV3 (subma1 [0 ][6 ])
124+ HighscoreDataValue = TibiaDataStringToIntegerV3 (subma1 [0 ][7 ])
125+ } else {
107126 HighscoreDataVocation = subma1 [0 ][3 ]
108127 HighscoreDataWorld = subma1 [0 ][4 ]
109128 HighscoreDataLevel = TibiaDataStringToIntegerV3 (subma1 [0 ][5 ])
110129 HighscoreDataValue = TibiaDataStringToIntegerV3 (subma1 [0 ][6 ])
111- } else {
112- HighscoreDataVocation = subma1 [0 ][2 ]
113- HighscoreDataWorld = subma1 [0 ][3 ]
114- HighscoreDataLevel = TibiaDataStringToIntegerV3 (subma1 [0 ][4 ])
115- HighscoreDataValue = TibiaDataStringToIntegerV3 (subma1 [0 ][5 ])
116130 }
117131
118132 HighscoreData = append (HighscoreData , Highscore {
119133 Rank : HighscoreDataRank ,
120- Name : TibiaDataSanitizeEscapedString (subma1 [0 ][1 ]),
134+ Name : TibiaDataSanitizeEscapedString (subma1 [0 ][2 ]),
121135 Vocation : HighscoreDataVocation ,
122136 World : HighscoreDataWorld ,
123137 Level : HighscoreDataLevel ,
@@ -139,6 +153,11 @@ func TibiaHighscoresV3Impl(world string, category HighscoreCategory, vocationNam
139153 Vocation : vocationName ,
140154 HighscoreAge : HighscoreAge ,
141155 HighscoreList : HighscoreData ,
156+ HighscorePage : HighscorePage {
157+ CurrentPage : currentPage ,
158+ TotalPages : HighscoreTotalPages ,
159+ TotalHighscores : HighscoreTotalHighscores ,
160+ },
142161 },
143162 Information {
144163 APIVersion : TibiaDataAPIversion ,
0 commit comments