Skip to content

Commit

Permalink
Handle missing Eureka data (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Nov 25, 2021
1 parent 12f0d58 commit 66e1212
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions classjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (s *Scraper) buildClassJobCollector(charData *Character) *colly.Collector {

c.OnHTML(classJobSelectors.Bozja.Mettle.Selector, func(e *colly.HTMLElement) {
mettleStr := classJobSelectors.Bozja.Mettle.Parse(e)[0]
cjb.mettleRaw = e // TODO: https://github.com/xivapi/godestone/issues/17

mettleStr = nonDigits.ReplaceAllString(mettleStr, "")
mettle, err := strconv.ParseUint(mettleStr, 10, 32)
if err == nil {
Expand Down
8 changes: 5 additions & 3 deletions records.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package godestone
import (
"time"

"github.com/gocolly/colly/v2"
"github.com/xivapi/godestone/v2/data/baseparam"
"github.com/xivapi/godestone/v2/data/gcrank"
"github.com/xivapi/godestone/v2/data/gender"
Expand Down Expand Up @@ -106,9 +107,10 @@ type ClassJob struct {

// ClassJobBozja represents character progression data in the Bozjan Southern Front.
type ClassJobBozja struct {
Level uint8
Mettle uint32
Name string
Level uint8
Mettle uint32
mettleRaw *colly.HTMLElement // TODO: https://github.com/xivapi/godestone/issues/17
Name string
}

// ClassJobEureka represents character progression data in Eureka.
Expand Down
41 changes: 41 additions & 0 deletions scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"sync"
"time"

Expand All @@ -13,6 +14,14 @@ import (
"github.com/xivapi/godestone/v2/provider"
)

// Used for a band-aid in the Character scraper
var elementalLevelNames = map[string]struct{}{
"Elemental Level": {},
"Elementarstufe": {},
"Niveau élémentaire": {},
"エレメンタルレベル": {},
}

// Scraper is the object through which interactions with The Lodestone are made.
type Scraper struct {
lang SiteLang
Expand Down Expand Up @@ -131,12 +140,44 @@ func (s *Scraper) FetchCharacter(id uint32) (*Character, error) {
}
}

// Link the active classjob details from the classjob page
for _, cj := range charData.ClassJobs {
if cj.Name == activeClassJobName {
charData.ActiveClassJob = cj
}
}

// TODO: https://github.com/xivapi/godestone/issues/17 Ugly band-aid
// If the Bozja struct has Eureka data, we'll just move the data
// over and clear the Bozja struct for the time being. This is
// implemented as unintrusively as possible so that we can rip it
// out as soon as a better solution becomes available.
if _, ok := elementalLevelNames[charData.ClassJobBozjan.Name]; ok {
charData.ClassJobElemental.Level = charData.ClassJobBozjan.Level
charData.ClassJobElemental.Name = charData.ClassJobBozjan.Name

expStrs := s.profileSelectors.ClassJob.Eureka.Exp.Parse(charData.ClassJobBozjan.mettleRaw)
expStrs[0] = nonDigits.ReplaceAllString(expStrs[0], "")
expStrs[1] = nonDigits.ReplaceAllString(expStrs[1], "")

curExp, err := strconv.ParseUint(expStrs[0], 10, 32)
if err == nil {
charData.ClassJobElemental.ExpLevel = uint32(curExp)
}

maxExp, err := strconv.ParseUint(expStrs[1], 10, 32)
if err == nil {
charData.ClassJobElemental.ExpLevelMax = uint32(maxExp)
}

charData.ClassJobElemental.ExpLevelTogo = charData.ClassJobElemental.ExpLevelMax - charData.ClassJobElemental.ExpLevel

// Clear old data
charData.ClassJobBozjan.Level = 0
charData.ClassJobBozjan.Mettle = 0
charData.ClassJobBozjan.Name = ""
}

return &charData, nil
}

Expand Down

0 comments on commit 66e1212

Please sign in to comment.