From f74c7ead33c33f46572ccfddca749a7ea86f01fc Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Sat, 29 Jan 2022 00:35:18 +0100 Subject: [PATCH 1/2] removing TruncatedDeaths --- src/TibiaCharactersCharacterV3.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/TibiaCharactersCharacterV3.go b/src/TibiaCharactersCharacterV3.go index 64765947..87221c54 100644 --- a/src/TibiaCharactersCharacterV3.go +++ b/src/TibiaCharactersCharacterV3.go @@ -79,8 +79,7 @@ type DeathEntries struct { // Child of Characters type Deaths struct { - DeathEntries []DeathEntries `json:"death_entries,omitempty"` - TruncatedDeaths bool `json:"truncated,omitempty"` // deathlist can be truncated.. but we don't have logic for that atm + DeathEntries []DeathEntries `json:"death_entries,omitempty"` } // Child of Characters @@ -320,7 +319,6 @@ func TibiaCharactersCharacterV3Impl(BoxContentHTML string) CharacterResponse { // Removing line breaks CharacterListHTML = TibiadataHTMLRemoveLinebreaksV3(CharacterListHTML) - //log.Println(CharacterListHTML) CharacterListHTML = strings.ReplaceAll(CharacterListHTML, ".
Assisted by", ". Assisted by") // Regex to get data for deaths From 314ac5d5631892f0d28c1a05960ad05cb24fe3c1 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Sat, 29 Jan 2022 00:40:46 +0100 Subject: [PATCH 2/2] slimming down deaths - switching from object to array of object --- src/TibiaCharactersCharacterV3.go | 17 ++++++----------- src/TibiaCharactersCharacterV3_test.go | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/TibiaCharactersCharacterV3.go b/src/TibiaCharactersCharacterV3.go index 87221c54..a4d8c7c4 100644 --- a/src/TibiaCharactersCharacterV3.go +++ b/src/TibiaCharactersCharacterV3.go @@ -60,7 +60,7 @@ type Achievements struct { Secret bool `json:"secret"` } -// Child of DeathEntries +// Child of Deaths type Killers struct { Name string `json:"name"` Player bool `json:"player"` @@ -68,8 +68,8 @@ type Killers struct { Summon string `json:"summon"` } -// Child of Deaths -type DeathEntries struct { +// Child of Characters +type Deaths struct { Time string `json:"time"` Level int `json:"level"` Killers []Killers `json:"killers"` @@ -77,11 +77,6 @@ type DeathEntries struct { Reason string `json:"reason"` } -// Child of Characters -type Deaths struct { - DeathEntries []DeathEntries `json:"death_entries,omitempty"` -} - // Child of Characters type AccountInformation struct { Position string `json:"position,omitempty"` @@ -104,7 +99,7 @@ type Characters struct { Character Character `json:"character"` AccountBadges []AccountBadges `json:"account_badges,omitempty"` Achievements []Achievements `json:"achievements,omitempty"` - Deaths Deaths `json:"deaths,omitempty"` + Deaths []Deaths `json:"deaths,omitempty"` AccountInformation AccountInformation `json:"account_information,omitempty"` OtherCharacters []OtherCharacters `json:"other_characters,omitempty"` } @@ -143,7 +138,7 @@ func TibiaCharactersCharacterV3Impl(BoxContentHTML string) CharacterResponse { CharacterInformationData Character AccountBadgesData []AccountBadges AchievementsData []Achievements - DeathsData Deaths + DeathsData []Deaths AccountInformationData AccountInformation OtherCharactersData []OtherCharacters ) @@ -386,7 +381,7 @@ func TibiaCharactersCharacterV3Impl(BoxContentHTML string) CharacterResponse { } // append deadentry to death list - DeathsData.DeathEntries = append(DeathsData.DeathEntries, DeathEntries{ + DeathsData = append(DeathsData, Deaths{ Time: TibiadataDatetimeV3(subma1[0][1]), Level: TibiadataStringToIntegerV3(subma1[0][3]), Killers: DeathKillers, diff --git a/src/TibiaCharactersCharacterV3_test.go b/src/TibiaCharactersCharacterV3_test.go index 17e5b67b..8f846d0e 100644 --- a/src/TibiaCharactersCharacterV3_test.go +++ b/src/TibiaCharactersCharacterV3_test.go @@ -129,9 +129,9 @@ func TestNumber4(t *testing.T) { assert.Equal("Nataraya Soldrac", characterJson.Characters.Character.FormerNames[3]) //validate death data - assert.Equal(79, len(characterJson.Characters.Deaths.DeathEntries)) + assert.Equal(79, len(characterJson.Characters.Deaths)) - firstDeath := characterJson.Characters.Deaths.DeathEntries[0] + firstDeath := characterJson.Characters.Deaths[0] assert.Equal(28, len(firstDeath.Killers)) }