Skip to content

Commit

Permalink
Fix extract overview ships
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Oct 3, 2022
1 parent e940fcf commit 7449053
Show file tree
Hide file tree
Showing 4 changed files with 1,808 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/extractor/v9/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (e *Extractor) ExtractOverviewProduction(pageHTML []byte) ([]ogame.Quantifi

// ExtractOverviewProductionFromDoc extracts ships/defenses (partial) production from the overview page
func (e *Extractor) ExtractOverviewProductionFromDoc(doc *goquery.Document) ([]ogame.Quantifiable, error) {
return extractOverviewProductionFromDoc(doc)
return extractOverviewProductionFromDoc(doc, e.GetLifeformEnabled())
}

// ExtractEspionageReport ...
Expand Down
10 changes: 10 additions & 0 deletions pkg/extractor/v9/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,13 @@ func TestExtractTechnologyDetails(t *testing.T) {
details, _ = NewExtractor().ExtractTechnologyDetails(pageHTMLBytes)
assert.True(t, details.TearDownEnabled)
}

func TestExtractOverviewProduction_ships(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.5/en/overview_ships.html")
prod, _, _ := NewExtractor().ExtractOverviewProduction(pageHTMLBytes)
assert.Equal(t, 2, len(prod))
assert.Equal(t, ogame.SmallCargoID, prod[0].ID)
assert.Equal(t, int64(1), prod[0].Nbr)
assert.Equal(t, ogame.SmallCargoID, prod[1].ID)
assert.Equal(t, int64(1), prod[1].Nbr)
}
7 changes: 5 additions & 2 deletions pkg/extractor/v9/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ func extractEmpire(pageHTML []byte) ([]ogame.EmpireCelestial, error) {
return out, nil
}

func extractOverviewProductionFromDoc(doc *goquery.Document) ([]ogame.Quantifiable, error) {
func extractOverviewProductionFromDoc(doc *goquery.Document, lifeformEnabled bool) ([]ogame.Quantifiable, error) {
res := make([]ogame.Quantifiable, 0)
active := doc.Find("table.construction").Eq(4)
active := doc.Find("table.construction").Eq(2)
if lifeformEnabled {
active = doc.Find("table.construction").Eq(4)
}
href, _ := active.Find("td a").Attr("href")
m := regexp.MustCompile(`openTech=(\d+)`).FindStringSubmatch(href)
if len(m) == 0 {
Expand Down
Loading

0 comments on commit 7449053

Please sign in to comment.