Skip to content

Commit

Permalink
extract moon infos from galaxy
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 27, 2018
1 parent 547f713 commit fb3bf38
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,14 @@ func extractGalaxyInfos(pageHTML, lang string) ([]PlanetInfos, error) {

planetInfos := PlanetInfos{}

moonID, _ := strconv.Atoi(s.Find("td.moon").AttrOr("data-moon-id", ""))
moonSize, _ := strconv.Atoi(strings.Split(s.Find("td.moon span#moonsize").Text(), " ")[0])
if moonID > 0 {
planetInfos.Moon = new(MoonInfos)
planetInfos.Moon.ID = moonID
planetInfos.Moon.Diameter = moonSize
}

allianceSpan := s.Find("span.allytagwrapper")
if allianceSpan.Size() > 0 {
longID, _ := allianceSpan.Attr("rel")
Expand Down
8 changes: 8 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ func TestExtractGalaxyInfos_strongPlayer(t *testing.T) {
assert.False(t, infos[2].StrongPlayer)
}

func TestExtractGalaxyInfos_moon(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_debris.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "en")
assert.NotNil(t, infos[0].Moon)
assert.Equal(t, 33701543, infos[0].Moon.ID)
assert.Equal(t, 8366, infos[0].Moon.Diameter)
}

func TestExtractGalaxyInfos_debris(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_debris.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "en")
Expand Down
6 changes: 6 additions & 0 deletions planetInfos.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ogame

type MoonInfos struct {
ID int
Diameter int
}

// PlanetInfos ...
type PlanetInfos struct {
Activity int
Expand All @@ -16,6 +21,7 @@ type PlanetInfos struct {
Crystal int
RecyclersNeeded int
}
Moon *MoonInfos
Player struct {
ID int
Name string
Expand Down

0 comments on commit fb3bf38

Please sign in to comment.