diff --git a/pkg/extractor/v6/extractor.go b/pkg/extractor/v6/extractor.go index 72f731e8..2255a2f8 100644 --- a/pkg/extractor/v6/extractor.go +++ b/pkg/extractor/v6/extractor.go @@ -546,7 +546,7 @@ func (e *Extractor) ExtractFleetsFromDoc(doc *goquery.Document) (res []ogame.Fle } func (e *Extractor) extractFleetsFromDoc(doc *goquery.Document, location *time.Location) (res []ogame.Fleet) { - return extractFleetsFromDoc(doc, location) + return extractFleetsFromDoc(doc, location, e.lifeformEnabled) } // ExtractSlotsFromDoc extract fleet slots from page "fleet1" diff --git a/pkg/extractor/v6/extracts.go b/pkg/extractor/v6/extracts.go index b02089c7..5fcefeb5 100644 --- a/pkg/extractor/v6/extracts.go +++ b/pkg/extractor/v6/extracts.go @@ -1090,7 +1090,7 @@ func extractIPMFromDoc(doc *goquery.Document) (duration, max int64, token string return } -func extractFleetsFromDoc(doc *goquery.Document, location *time.Location) (res []ogame.Fleet) { +func extractFleetsFromDoc(doc *goquery.Document, location *time.Location, lifeformEnabled bool) (res []ogame.Fleet) { res = make([]ogame.Fleet, 0) script := doc.Find("body script").Text() doc.Find("div.fleetDetails").Each(func(i int, s *goquery.Selection) { @@ -1134,9 +1134,17 @@ func extractFleetsFromDoc(doc *goquery.Document, location *time.Location) (res [ trs := s.Find("table.fleetinfo tr") shipment := ogame.Resources{} - shipment.Metal = utils.ParseInt(trs.Eq(trs.Size() - 3).Find("td").Eq(1).Text()) - shipment.Crystal = utils.ParseInt(trs.Eq(trs.Size() - 2).Find("td").Eq(1).Text()) - shipment.Deuterium = utils.ParseInt(trs.Eq(trs.Size() - 1).Find("td").Eq(1).Text()) + metalTrOffset := 3 + crystalTrOffset := 2 + DeuteriumTrOffset := 1 + if lifeformEnabled { + metalTrOffset = 4 + crystalTrOffset = 3 + DeuteriumTrOffset = 2 + } + shipment.Metal = utils.ParseInt(trs.Eq(trs.Size() - metalTrOffset).Find("td").Eq(1).Text()) + shipment.Crystal = utils.ParseInt(trs.Eq(trs.Size() - crystalTrOffset).Find("td").Eq(1).Text()) + shipment.Deuterium = utils.ParseInt(trs.Eq(trs.Size() - DeuteriumTrOffset).Find("td").Eq(1).Text()) fedAttackHref := s.Find("span.fedAttack a").AttrOr("href", "") fedAttackURL, _ := url.Parse(fedAttackHref) diff --git a/pkg/extractor/v9/extractor_test.go b/pkg/extractor/v9/extractor_test.go index 03bbcd1e..de4de4e4 100644 --- a/pkg/extractor/v9/extractor_test.go +++ b/pkg/extractor/v9/extractor_test.go @@ -132,3 +132,14 @@ func TestExtractUserInfos(t *testing.T) { assert.Equal(t, int64(1102), info.Rank) assert.Equal(t, int64(2931), info.Total) } + +func TestExtractFleetResources(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/lifeform/movement.html") + e := NewExtractor() + e.SetLocation(time.FixedZone("OGT", 3600)) + e.SetLifeformEnabled(true) + fleets := e.ExtractFleets(pageHTMLBytes) + assert.Equal(t, int64(1), fleets[0].Resources.Metal) + assert.Equal(t, int64(2), fleets[0].Resources.Crystal) + assert.Equal(t, int64(3), fleets[0].Resources.Deuterium) +} diff --git a/samples/v9.0.4/en/lifeform/movement.html b/samples/v9.0.4/en/lifeform/movement.html new file mode 100644 index 00000000..d2175939 --- /dev/null +++ b/samples/v9.0.4/en/lifeform/movement.html @@ -0,0 +1,1765 @@ + + + +
++ + load... + + | +10:07:48 Clock | ++ + | + ++ Homeworld + | ++ + [2:138:12] + + | + ++ 1 + | ++ + + + | + ++ Colony + | ++ + [2:138:5] + + | + ++ | ++ | +
+ + load... + + | +15:50:31 Clock | ++ + | + ++ Homeworld + | ++ + [2:138:12] + + | + ++ 1 + | ++ + + + | + ++ Colony + | ++ + [2:138:5] + + | + ++ | ++ | +
+ 5/5 Planets +
+