From a5552d31029898b9e9cffcf10af044c9622c4b72 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Fri, 23 Sep 2022 20:29:10 -0700 Subject: [PATCH] Fix fleets resources (lifeform) --- pkg/extractor/v6/extractor.go | 2 +- pkg/extractor/v6/extracts.go | 16 +- pkg/extractor/v9/extractor_test.go | 11 + samples/v9.0.4/en/lifeform/movement.html | 1765 ++++++++++++++++++++++ 4 files changed, 1789 insertions(+), 5 deletions(-) create mode 100644 samples/v9.0.4/en/lifeform/movement.html 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 @@ + + + + + Halley OGame + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ + +
+ + + + + + +
+ +
+ + + + + +
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ + 471,747 + +
+
+
+
+
+ + 222,828 + +
+
+
+
+
+ + 175,011 + +
+
+
+
+
+ + -2,267 + +
+
+
+
+
+ + 1,974,118.233 + +
+
+
+
+
+ + 0 + +
+
+
+
+ + +
+
+ + 8,000 + +
+
+
+ +
+ +
+
+ + + 24 + + + + + 0 + + +
+ +
+ ajax spinner + load... +
+ +
+
+ +
+
+
+ +
+
+
+
+ ? +
+
+
+
+
+
+ +
+ + + + + + +
+
+ +
+
+
+
+
+
+
+ + +

Events

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + 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] + + + +
+
+
+
+ + + +
+
+
+
+
+

Fleet movement - Homeworld

+ + + +
+
+
+
+ + + + Reload + + + + Fleets: 1 / 12 + + + Expeditions: 0 / 2 + + + + + + +
+
+ load... + 10:07:48 Clock + Transport + + + [2:138:12] + +
Homeworld +
+
+ + + + + + + + + + + + +
+
+ +
+ +
+ + + + + +
+ +
+ +
+
+
+ + + +
Colony +
+
+ + [2:138:5] +
+ load... + 15:50:31 Clock + Return + + + + + + +
+
+
+
+ +
+
+ +
+
+
+ + + + + +
+
+ +
+ +
+
    +
  • +
    +
    + 0 Contact(s) online +
  • +
+ + +
+
+ + + +