Skip to content

Commit

Permalink
Add moon activity
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 13, 2018
1 parent 22a6886 commit 8fdecb3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,10 +1684,12 @@ func extractGalaxyInfos(pageHTML, botPlayerName string, botPlayerID, botPlayerRa

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

allianceSpan := s.Find("span.allytagwrapper")
Expand Down
18 changes: 18 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ func TestExtractGalaxyInfosOwnPlanet(t *testing.T) {
assert.Equal(t, "Homeworld", infos[4].Name)
}

func TestExtractGalaxyInfosMoonActivity(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_moon_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
assert.Equal(t, 3, len(infos))
assert.Equal(t, 33732827, infos[0].Moon.ID)
assert.Equal(t, 5830, infos[0].Moon.Diameter)
assert.Equal(t, 18, infos[0].Moon.Activity)
}

func TestExtractGalaxyInfosMoonNoActivity(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_moon_no_activity.html")
infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456)
assert.Equal(t, 3, len(infos))
assert.Equal(t, 33650476, infos[0].Moon.ID)
assert.Equal(t, 7897, infos[0].Moon.Diameter)
assert.Equal(t, 0, infos[0].Moon.Activity)
}

func TestExtractUserInfos(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/overview_inactive.html")
infos, _ := extractUserInfos(string(pageHTMLBytes), "en")
Expand Down
1 change: 1 addition & 0 deletions planetInfos.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ogame
type MoonInfos struct {
ID int
Diameter int
Activity int
}

type AllianceInfos struct {
Expand Down
1 change: 1 addition & 0 deletions samples/galaxy_moon_activity.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions samples/galaxy_moon_no_activity.html

Large diffs are not rendered by default.

0 comments on commit 8fdecb3

Please sign in to comment.