diff --git a/pkg/extractor/v6/extracts.go b/pkg/extractor/v6/extracts.go index f0777a9f..b02089c7 100644 --- a/pkg/extractor/v6/extracts.go +++ b/pkg/extractor/v6/extracts.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/json" "errors" - "github.com/alaingilbert/ogame/pkg/ogame" - "github.com/alaingilbert/ogame/pkg/utils" "math" "net/url" "regexp" @@ -13,6 +11,9 @@ import ( "strings" "time" + "github.com/alaingilbert/ogame/pkg/ogame" + "github.com/alaingilbert/ogame/pkg/utils" + "github.com/PuerkitoBio/goquery" "github.com/alaingilbert/clockwork" lua "github.com/yuin/gopher-lua" @@ -1509,7 +1510,7 @@ func extractUserInfos(pageHTML []byte, lang string) (ogame.UserInfos, error) { res := ogame.UserInfos{} res.PlayerID = int64(utils.ToInt(playerIDGroups[1])) res.PlayerName = string(playerNameGroups[1]) - html2 := subHTMLGroups[1] + html2 := []byte(strings.ReplaceAll(string(subHTMLGroups[1]), ",", ".")) infosRgx := regexp.MustCompile(`([\d\\.]+) \(Place ([\d.]+) of ([\d.]+)\)`) switch lang { diff --git a/pkg/extractor/v874/extracts.go b/pkg/extractor/v874/extracts.go index a54c8af7..3c90b10f 100644 --- a/pkg/extractor/v874/extracts.go +++ b/pkg/extractor/v874/extracts.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" + "regexp" + "strings" + "github.com/PuerkitoBio/goquery" "github.com/alaingilbert/ogame/pkg/ogame" "github.com/alaingilbert/ogame/pkg/utils" - "regexp" - "strings" ) func extractBuffActivationFromDoc(doc *goquery.Document) (token string, items []ogame.Item, err error) { diff --git a/pkg/extractor/v9/extractor.go b/pkg/extractor/v9/extractor.go index ccf7c36c..f76499ef 100644 --- a/pkg/extractor/v9/extractor.go +++ b/pkg/extractor/v9/extractor.go @@ -2,9 +2,10 @@ package v9 import ( "bytes" + "github.com/PuerkitoBio/goquery" "github.com/alaingilbert/clockwork" - "github.com/alaingilbert/ogame/pkg/extractor/v874" + v874 "github.com/alaingilbert/ogame/pkg/extractor/v874" "github.com/alaingilbert/ogame/pkg/ogame" ) @@ -83,3 +84,12 @@ func (e *Extractor) ExtractResourcesDetailsFromFullPageFromDoc(doc *goquery.Docu func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64) { return ExtractConstructions(pageHTML, clockwork.NewRealClock()) } + +func (e *Extractor) ExtractResourceSettings(pageHTML []byte) (ogame.ResourceSettings, string, error) { + doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML)) + return e.ExtractResourceSettingsFromDoc(doc) +} + +func (e *Extractor) ExtractResourceSettingsFromDoc(doc *goquery.Document) (ogame.ResourceSettings, string, error) { + return extractResourceSettingsFromDoc(doc) +} diff --git a/pkg/extractor/v9/extractor_test.go b/pkg/extractor/v9/extractor_test.go index f5bf6bd2..03bbcd1e 100644 --- a/pkg/extractor/v9/extractor_test.go +++ b/pkg/extractor/v9/extractor_test.go @@ -1,12 +1,13 @@ package v9 import ( - "github.com/alaingilbert/clockwork" - "github.com/alaingilbert/ogame/pkg/ogame" - "github.com/stretchr/testify/assert" "io/ioutil" "testing" "time" + + "github.com/alaingilbert/clockwork" + "github.com/alaingilbert/ogame/pkg/ogame" + "github.com/stretchr/testify/assert" ) func TestExtractResourcesDetailsFromFullPage(t *testing.T) { @@ -116,3 +117,18 @@ func TestGetConstructions(t *testing.T) { assert.Equal(t, ogame.ComputerTechnologyID, researchID) assert.Equal(t, int64(18355), researchCountdown) } + +func TestExtractResourceSettings(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/resource_settings.html") + settings, _, _ := NewExtractor().ExtractResourceSettings(pageHTMLBytes) + assert.Equal(t, ogame.ResourceSettings{MetalMine: 100, CrystalMine: 100, DeuteriumSynthesizer: 100, SolarPlant: 100, FusionReactor: 100, SolarSatellite: 100, Crawler: 100, PlasmaTechnology: 100}, settings) +} + +func TestExtractUserInfos(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/overview.html") + info, err := NewExtractor().ExtractUserInfos(pageHTMLBytes) + assert.NoError(t, err) + assert.Equal(t, int64(30478), info.Points) + assert.Equal(t, int64(1102), info.Rank) + assert.Equal(t, int64(2931), info.Total) +} diff --git a/pkg/extractor/v9/extracts.go b/pkg/extractor/v9/extracts.go index ecd9b4a7..5c9f727d 100644 --- a/pkg/extractor/v9/extracts.go +++ b/pkg/extractor/v9/extracts.go @@ -2,16 +2,17 @@ package v9 import ( "errors" + "regexp" + "strings" + "time" + "github.com/PuerkitoBio/goquery" "github.com/alaingilbert/clockwork" - "github.com/alaingilbert/ogame/pkg/extractor/v6" + v6 "github.com/alaingilbert/ogame/pkg/extractor/v6" v7 "github.com/alaingilbert/ogame/pkg/extractor/v7" - "github.com/alaingilbert/ogame/pkg/extractor/v71" + v71 "github.com/alaingilbert/ogame/pkg/extractor/v71" "github.com/alaingilbert/ogame/pkg/ogame" "github.com/alaingilbert/ogame/pkg/utils" - "regexp" - "strings" - "time" ) func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64) { @@ -532,3 +533,40 @@ func extractEspionageReportFromDoc(doc *goquery.Document, location *time.Locatio } return report, nil } + +func extractResourceSettingsFromDoc(doc *goquery.Document) (ogame.ResourceSettings, string, error) { + bodyID := v6.ExtractBodyIDFromDoc(doc) + if bodyID == "overview" { + return ogame.ResourceSettings{}, "", ogame.ErrInvalidPlanetID + } + vals := make([]int64, 0) + doc.Find("option").Each(func(i int, s *goquery.Selection) { + _, selectedExists := s.Attr("selected") + if selectedExists { + a, _ := s.Attr("value") + val := utils.DoParseI64(a) + vals = append(vals, val) + } + }) + + if len(vals) != 8 { + return ogame.ResourceSettings{}, "", errors.New("failed to find all resource settings") + } + + res := ogame.ResourceSettings{} + res.MetalMine = vals[0] + res.CrystalMine = vals[1] + res.DeuteriumSynthesizer = vals[2] + res.SolarPlant = vals[3] + res.FusionReactor = vals[4] + res.SolarSatellite = vals[5] + res.Crawler = vals[6] + res.PlasmaTechnology = vals[7] + + token, exists := doc.Find("form input[name=token]").Attr("value") + if !exists { + return ogame.ResourceSettings{}, "", errors.New("unable to find token") + } + + return res, token, nil +} diff --git a/pkg/ogame/resourceSettings.go b/pkg/ogame/resourceSettings.go index b5be0868..37e7941d 100644 --- a/pkg/ogame/resourceSettings.go +++ b/pkg/ogame/resourceSettings.go @@ -11,6 +11,7 @@ type ResourceSettings struct { FusionReactor int64 SolarSatellite int64 Crawler int64 + PlasmaTechnology int64 } func (r ResourceSettings) String() string { @@ -21,5 +22,6 @@ func (r ResourceSettings) String() string { " Solar Plant: " + utils.FI64(r.SolarPlant) + "\n" + " Fusion Reactor: " + utils.FI64(r.FusionReactor) + "\n" + " Solar Satellite: " + utils.FI64(r.SolarSatellite) + "\n" + - " Crawler: " + utils.FI64(r.Crawler) + " Crawler: " + utils.FI64(r.Crawler) + "\n" + + " Plasma Technology: " + utils.FI64(r.PlasmaTechnology) } diff --git a/pkg/ogame/resourceSettings_test.go b/pkg/ogame/resourceSettings_test.go index 1bbe24d8..3beae2ad 100644 --- a/pkg/ogame/resourceSettings_test.go +++ b/pkg/ogame/resourceSettings_test.go @@ -15,6 +15,7 @@ func TestResourceSettings_String(t *testing.T) { FusionReactor: 5, SolarSatellite: 6, Crawler: 7, + PlasmaTechnology: 8, } expected := "\n" + " Metal Mine: 1\n" + @@ -23,6 +24,7 @@ func TestResourceSettings_String(t *testing.T) { " Solar Plant: 4\n" + " Fusion Reactor: 5\n" + " Solar Satellite: 6\n" + - " Crawler: 7" + " Crawler: 7\n" + + " Plasma Technology: 8" assert.Equal(t, expected, r.String()) } diff --git a/samples/v9.0.4/en/overview.html b/samples/v9.0.4/en/overview.html new file mode 100644 index 00000000..cdb086f6 --- /dev/null +++ b/samples/v9.0.4/en/overview.html @@ -0,0 +1,1696 @@ + + + + + Ferdinand OGame + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ +
+ + + + +
+
+
+
+
+ +
+
+
+
+
+ + + +
+
+ + + + + + +
+ +
+ + + + + +
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ + 3,693,664 + +
+
+
+
+
+ + 2,019,427 + +
+
+
+
+
+ + 1,690,612 + +
+
+
+
+
+ + -2,899 + +
+
+
+
+ + +
+
+ + 8,000 + +
+
+
+ +
+ +
+
+ + + 8 + + + + + 1 + + +
+ +
+ ajax spinner + load... +
+ +
+
+ +
+
+
+ +
+
+
+
+ ? +
+
+
+
+
+
+ +
+ + + + + + +
+
+ +
+
+
+
+ + + + +
+
+ +
+
+
+ + +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + +
+
+ + +
+
+ +
+
+ +
+ +
+ + +
+
+
+
+
+
+
+

Buildings

+
+ + +
+ +
+
+
+
+ +
+
+
+ +
+
+

Shipyard

+
+ + +
+ +
+
+
+ + + +
+
+ +
+
+
+ + + + + +
+
+ +
+ +
+ + + +
+
+ + + + diff --git a/samples/v9.0.4/en/resource_settings.html b/samples/v9.0.4/en/resource_settings.html new file mode 100644 index 00000000..15a9776d --- /dev/null +++ b/samples/v9.0.4/en/resource_settings.html @@ -0,0 +1,2042 @@ + + + + + Ferdinand OGame + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + + + + +
+ +
+ + + + + +
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ + 3,759,336 + +
+
+
+
+
+ + 2,055,665 + +
+
+
+
+
+ + 1,714,574 + +
+
+
+
+
+ + -2,899 + +
+
+
+
+ + +
+
+ + 8,000 + +
+
+
+ +
+ +
+
+ + + 6 + + + + + 1 + + +
+ +
+ ajax spinner + load... +
+ +
+
+ +
+
+
+ +
+
+
+
+ ? +
+
+
+
+
+
+ +
+ + + + + + +
+
+ +
+
+
+
+ + + + +
+
+
+
+

Resource settings - Homeworld

+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ Production factor: 48% + + + +
+
+
+
Basic Income + 180 + + 90 + + 0 + + 0 +
+ Metal Mine (Level 21) + + + + 27,972 + + + + 0 + + + + 0 + + + + 747/1,554 + + + +
+ Crystal Mine (Level 20) + + + + 0 + + + + 16,145 + + + + 0 + + + + 647/1,345 + + + +
+ Deuterium Synthesizer (Level 20) + + + + 0 + + + + 0 + + + + 10,688 + + + + 1,294/2,690 + + + +
+ Solar Plant (Level 20) + + + + 0 + + + + 0 + + + + 0 + + + + 5,589 + + + +
+ Fusion Reactor (Level 0) + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + +
+ Solar Satellite (Number: 0) + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + +
+ Crawler (Number: 0/488) + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + +
+ Plasma Technology (Level 0) + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + +
+ Items + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
+ Geologist + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
+ Engineer + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
+ Commanding Staff + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
+ Class + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
+ Alliance Class + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + +
Storage capacity + + 5Mn + + + + 5Mn + + + + 5Mn + + + + 0 + +
Total per hour: + + 13,642 + + + + 7,860 + + + + 5,144 + + + + 5,589/2,690 + +
Total per day: + + 327,431 + + + + 188,655 + + + + 123,459 + + + + 5,589/2,690 + +
Total per week: + + 2Mn + + + + 1Mn + + + + 864,219 + + + + 5,589/2,690 + +
+
+
+
+
+
+
+ + +
+
+ +
+
+
+ + + + + +
+
+ +
+ +
+ + + +
+
+ + + +