Skip to content

Commit

Permalink
fix regex for spain servers
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 24, 2018
1 parent 199cafc commit 36d82d0
Show file tree
Hide file tree
Showing 3 changed files with 1,246 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ type resourcesResp struct {
HonorScore int
}

var planetInfosRgx = regexp.MustCompile(`([^\[]+) \[(\d+):(\d+):(\d+)]([\d.]+)km \((\d+)/(\d+)\)([-\d]+).+C (?:bis|to|à) ([-\d]+).+C`)
var planetInfosRgx = regexp.MustCompile(`([^\[]+) \[(\d+):(\d+):(\d+)]([\d.]+)km \((\d+)/(\d+)\)(?:de )?([-\d]+).+C\s*(?:bis|to|à|a) ([-\d]+).+C`)

func extractPlanets(pageHTML string, b *OGame) []Planet {
res := make([]Planet, 0)
Expand Down
15 changes: 15 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ func TestExtractPlanets(t *testing.T) {
assert.Equal(t, 12800, planets[0].Diameter)
}

func TestExtractPlanets_es(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/overview_es.html")
planets := extractPlanets(string(pageHTMLBytes), &OGame{language: "es"})
assert.Equal(t, 1, len(planets))
assert.Equal(t, PlanetID(33630486), planets[0].ID)
assert.Equal(t, Coordinate{Galaxy: 2, System: 147, Position: 8}, planets[0].Coordinate)
assert.Equal(t, "Planeta Prin...", planets[0].Name)
assert.Equal(t, "https://gf2.geo.gfsrv.net/cdnd1/83579badf7c16d217b06afda455cfe.png", planets[0].Img)
assert.Equal(t, 18, planets[0].Temperature.Min)
assert.Equal(t, 58, planets[0].Temperature.Max)
assert.Equal(t, 0, planets[0].Fields.Built)
assert.Equal(t, 193, planets[0].Fields.Total)
assert.Equal(t, 12800, planets[0].Diameter)
}

func TestExtractPlanets_fr(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/fr_overview.html")
planets := extractPlanets(string(pageHTMLBytes), &OGame{language: "fr"})
Expand Down
Loading

0 comments on commit 36d82d0

Please sign in to comment.