Skip to content

Commit 41f35d7

Browse files
committed
Update API to scrape profile professions instead of character professions
1 parent 7c11dcf commit 41f35d7

File tree

5 files changed

+87
-34
lines changed

5 files changed

+87
-34
lines changed

docs/openapi.json

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"/v1/adventurer": {
119119
"get": {
120120
"summary": "Retrieve player's profile.",
121-
"description": "Retrieve the full profile of a single player by his or her profileTarget. Watch out for the \"privacy\" attribute that is added to the response when the player whose profile is requested turned on at least one of the privacy options BDO website has. It is a single number that you can decode using bitmasks. `0b0001` for private character levels, `0b0010` for private guild, `0b0100` for private contribution points and `0b1000` for private lifeskill levels. If the attribute is equal to `0b1111` then everything is set to private.",
121+
"description": "Retrieve the full profile of a single player by his or her profileTarget. Watch out for the \"privacy\" attribute that is added to the response when the player whose profile is requested turned on at least one of the privacy options BDO website has. It is a single number that you can decode using bitmasks. `0b0001` for private character levels, `0b0010` for private guild, `0b0100` for private contribution points and `0b1000` for private lifeskill levels. If the attribute is equal to `0b1111` then everything is set to private.\n\n<b>Important!</b> Property \"specLevels\" used to be on a character level, but BDO has changed it so that all characters have shared profession levels. This API will continue to return \"specLevels\" on the character level alongside with \"specLevels\" on the profile level for compatibility reasons until 1 September 2024.",
122122
"operationId": "getAdventurer",
123123
"parameters": [
124124
{
@@ -208,6 +208,7 @@
208208
"example": 56
209209
},
210210
"specLevels": {
211+
"deprecated": true,
211212
"properties": {
212213
"gathering": {
213214
"type": "string",
@@ -257,6 +258,54 @@
257258
}
258259
}
259260
}
261+
},
262+
"specLevels": {
263+
"properties": {
264+
"gathering": {
265+
"type": "string",
266+
"example": "Beginner 6"
267+
},
268+
"fishing": {
269+
"type": "string",
270+
"example": "Master 18"
271+
},
272+
"hunting": {
273+
"type": "string",
274+
"example": "Beginner 1"
275+
},
276+
"cooking": {
277+
"type": "string",
278+
"example": "Beginner 4"
279+
},
280+
"alchemy": {
281+
"type": "string",
282+
"example": "Beginner 1"
283+
},
284+
"processing": {
285+
"type": "string",
286+
"example": "Beginner 9"
287+
},
288+
"training": {
289+
"type": "string",
290+
"example": "Apprentice 1"
291+
},
292+
"trading": {
293+
"type": "string",
294+
"example": "Apprentice 3"
295+
},
296+
"farming": {
297+
"type": "string",
298+
"example": "Beginner 1"
299+
},
300+
"sailing": {
301+
"type": "string",
302+
"example": "Beginner 1"
303+
},
304+
"barter": {
305+
"type": "string",
306+
"example": "Beginner 1"
307+
}
308+
}
260309
}
261310
}
262311
}

handlers/GetStatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ func GetStatus(w http.ResponseWriter, r *http.Request) {
2828
},
2929
"proxies": len(config.GetProxyList()),
3030
"uptime": time.Since(initTime).Round(time.Second).String(),
31-
"version": "1.5.5",
31+
"version": "1.6.0",
3232
})
3333
}

models/Character.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ type Character struct {
55
Class string `json:"class"`
66
Main bool `json:"main,omitempty"`
77
Level uint8 `json:"level,omitempty"`
8-
SpecLevels *Specs `json:"specLevels,omitempty"`
8+
SpecLevels *Specs `json:"specLevels,omitempty"` // Deprecated, will be removed on 1 September 2024
99
}

models/Profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ type Profile struct {
1818
CreatedOn *time.Time `json:"createdOn,omitempty"`
1919
Characters []Character `json:"characters,omitempty"`
2020
Privacy int8 `json:"privacy,omitempty"`
21+
SpecLevels *Specs `json:"specLevels,omitempty"`
2122
}

scrapers/ScrapeAdventurer.go

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,42 @@ func ScrapeAdventurer(region string, profileTarget string) (profile models.Profi
6262
}
6363
})
6464

65+
c.OnHTML(`.character_spec:not(.lock)`, func(e *colly.HTMLElement) {
66+
specLevels := [11]string{}
67+
68+
e.ForEach(".spec_level", func(ind int, el *colly.HTMLElement) {
69+
// "Beginner1" → "Beginner 1"
70+
i := regexp.MustCompile(`[0-9]`).FindStringIndex(el.Text)[0]
71+
wordLevel := el.Text[:i]
72+
73+
if region != "EU" && region != "NA" {
74+
translators.TranslateSpecLevel(&wordLevel)
75+
}
76+
77+
specLevels[ind] = wordLevel + " " + el.Text[i:]
78+
})
79+
80+
if len(specLevels[0]) > 0 {
81+
profile.SpecLevels = &models.Specs{
82+
Gathering: specLevels[0],
83+
Fishing: specLevels[1],
84+
Hunting: specLevels[2],
85+
Cooking: specLevels[3],
86+
Alchemy: specLevels[4],
87+
Processing: specLevels[5],
88+
Training: specLevels[6],
89+
Trading: specLevels[7],
90+
Farming: specLevels[8],
91+
Sailing: specLevels[9],
92+
Barter: specLevels[10],
93+
}
94+
}
95+
})
96+
6597
c.OnHTML(`.character_desc_area`, func(e *colly.HTMLElement) {
6698
character := models.Character{
67-
Class: e.ChildText(".character_info .character_symbol em:last-child"),
99+
Class: e.ChildText(".character_info .character_symbol em:last-child"),
100+
SpecLevels: profile.SpecLevels, // Deprecated, will be removed on 1 September 2024
68101
}
69102

70103
if region != "EU" && region != "NA" {
@@ -91,36 +124,6 @@ func ScrapeAdventurer(region string, profileTarget string) (profile models.Profi
91124
}
92125
}
93126

94-
if specLevels := [11]string{}; true {
95-
e.ForEach(".character_spec:not(.lock) .spec_level", func(ind int, el *colly.HTMLElement) {
96-
// "Beginner1" → "Beginner 1"
97-
i := regexp.MustCompile(`[0-9]`).FindStringIndex(el.Text)[0]
98-
wordLevel := el.Text[:i]
99-
100-
if region != "EU" && region != "NA" {
101-
translators.TranslateSpecLevel(&wordLevel)
102-
}
103-
104-
specLevels[ind] = wordLevel + " " + el.Text[i:]
105-
})
106-
107-
if len(specLevels[0]) > 0 {
108-
character.SpecLevels = &models.Specs{
109-
Gathering: specLevels[0],
110-
Fishing: specLevels[1],
111-
Hunting: specLevels[2],
112-
Cooking: specLevels[3],
113-
Alchemy: specLevels[4],
114-
Processing: specLevels[5],
115-
Training: specLevels[6],
116-
Trading: specLevels[7],
117-
Farming: specLevels[8],
118-
Sailing: specLevels[9],
119-
Barter: specLevels[10],
120-
}
121-
}
122-
}
123-
124127
profile.Characters = append(profile.Characters, character)
125128
})
126129

0 commit comments

Comments
 (0)