Skip to content

Commit 80e0e34

Browse files
authored
Fix adventurer search with no main character (#18)
1 parent 5b749e3 commit 80e0e34

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

docs/openapi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,17 @@
422422
"type": "object",
423423
"properties": {
424424
"familyName": {
425+
"nullable": false,
425426
"type": "string",
426427
"example": "Apple"
427428
},
428429
"profileTarget": {
430+
"nullable": false,
429431
"type": "string",
430432
"example": "XXX"
431433
},
432434
"region": {
435+
"nullable": false,
433436
"type": "string",
434437
"enum": [
435438
"EU",
@@ -438,31 +441,38 @@
438441
]
439442
},
440443
"guild": {
444+
"nullable": true,
441445
"properties": {
442446
"name": {
447+
"nullable": false,
443448
"type": "string",
444449
"example": "TumblrGirls"
445450
}
446451
}
447452
},
448453
"characters": {
454+
"nullable": true,
449455
"type": "array",
450456
"items": {
451457
"type": "object",
452458
"properties": {
453459
"name": {
460+
"nullable": false,
454461
"type": "string",
455462
"example": "Blue"
456463
},
457464
"class": {
465+
"nullable": false,
458466
"type": "string",
459467
"example": "Ninja"
460468
},
461469
"main": {
470+
"nullable": true,
462471
"type": "boolean",
463472
"example": true
464473
},
465474
"level": {
475+
"nullable": false,
466476
"type": "number",
467477
"example": 56
468478
}

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.8.0",
31+
"version": "1.8.1",
3232
})
3333
}

scrapers/ScrapeAdventurerSearch.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func ScrapeAdventurerSearch(region string, query string, searchType uint8, page
2222
Region: region,
2323
FamilyName: e.ChildText(".title a"),
2424
ProfileTarget: extractProfileTarget(e.ChildAttr(".title a", "href")),
25-
Characters: make([]models.Character, 1),
2625
}
2726

2827
if region != "SA" && region != "KR" {
@@ -35,21 +34,27 @@ func ScrapeAdventurerSearch(region string, query string, searchType uint8, page
3534
}
3635
}
3736

38-
profile.Characters[0].Class = e.ChildText(".name")
39-
profile.Characters[0].Name = e.ChildText(".text")
37+
// Sometimes site displays text "You have not set your main character."
38+
// instead of a character
39+
if len(e.ChildText(".name")) > 0 {
40+
profile.Characters = make([]models.Character, 1)
4041

41-
// Site displays the main character when searching by family name
42-
// And the searched character when searching by character name
43-
if searchType == 2 {
44-
profile.Characters[0].Main = true
45-
}
42+
profile.Characters[0].Class = e.ChildText(".name")
43+
profile.Characters[0].Name = e.ChildText(".text")
4644

47-
if region != "EU" && region != "NA" {
48-
translators.TranslateClassName(&profile.Characters[0].Class)
49-
}
45+
// Site displays the main character when searching by family name
46+
// And the searched character when searching by character name
47+
if searchType == 2 {
48+
profile.Characters[0].Main = true
49+
}
5050

51-
if level, err := strconv.Atoi(e.ChildText(".level")[3:]); err == nil {
52-
profile.Characters[0].Level = uint8(level)
51+
if region != "EU" && region != "NA" {
52+
translators.TranslateClassName(&profile.Characters[0].Class)
53+
}
54+
55+
if level, err := strconv.Atoi(e.ChildText(".level")[3:]); err == nil {
56+
profile.Characters[0].Level = uint8(level)
57+
}
5358
}
5459

5560
profiles = append(profiles, profile)

0 commit comments

Comments
 (0)