Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 12, 2018
1 parent 1553444 commit de79e0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 5 additions & 10 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ func extractAttacks(pageHTML string) []AttackEvent {
if missionType == Attack || missionType == MissileAttack {
coordsOrigin := strings.Trim(s.Find("td.coordsOrigin").Text(), " \r\t\n")
attack.Origin = extractCoord(coordsOrigin)
attackerIDStr, _ := s.Find("a.sendMail").Attr("data-playerid")
attack.AttackerID, _ = strconv.Atoi(attackerIDStr)
}
if missionType == MissileAttack {
attack.Missiles = parseInt(s.Find("td.detailsFleet span").First().Text())
}

// Get ships infos if available
Expand All @@ -1601,16 +1606,6 @@ func extractAttacks(pageHTML string) []AttackEvent {

attack.ArrivalTime = time.Unix(int64(arrivalTimeInt), 0)

if missionType == Attack || missionType == MissileAttack {
attackerIDStr, _ := s.Find("a.sendMail").Attr("data-playerid")
attack.AttackerID, _ = strconv.Atoi(attackerIDStr)
}

if missionType == MissileAttack {
missilesStr := s.Find("td.detailsFleet span").First().Text()
attack.Missiles, _ = strconv.Atoi(missilesStr)
}

attacks = append(attacks, attack)
}
doc.Find("tr.eventFleet").Each(tmp)
Expand Down
2 changes: 2 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func TestExtractAttacksWithoutShips(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/event_list_attack.html")
attacks := extractAttacks(string(pageHTMLBytes))
assert.Equal(t, 1, len(attacks))
assert.Equal(t, 100771, attacks[0].AttackerID)
assert.Equal(t, 0, attacks[0].Missiles)
assert.Nil(t, attacks[0].Ships)
}

Expand Down

0 comments on commit de79e0e

Please sign in to comment.