Skip to content

Commit

Permalink
Merge branch 'release/42.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 25, 2020
2 parents 2b7e8cf + 87dbed6 commit 9b8fc2a
Show file tree
Hide file tree
Showing 4 changed files with 697 additions and 4 deletions.
6 changes: 3 additions & 3 deletions extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ func extractAuctionFromDoc(doc *goquery.Document) (Auction, error) {
auction.Inventory, _ = strconv.ParseInt(doc.Find("span.level.amount").Text(), 10, 64)
auction.CurrentItem = strings.ToLower(doc.Find("img").First().AttrOr("alt", ""))
auction.CurrentItemLong = strings.ToLower(doc.Find("div.image_140px").First().Find("a").First().AttrOr("title", ""))
multiplierRegex := regexp.MustCompile(`multiplier=([^;]+);`).FindStringSubmatch(doc.Text())
multiplierRegex := regexp.MustCompile(`multiplier\s?=\s?([^;]+);`).FindStringSubmatch(doc.Text())
if len(multiplierRegex) != 2 {
return Auction{}, errors.New("failed to find auction multiplier")
}
Expand All @@ -2156,14 +2156,14 @@ func extractAuctionFromDoc(doc *goquery.Document) (Auction, error) {
}

// Find auctioneer token
tokenRegex := regexp.MustCompile(`auctioneerToken="([^"]+)";`).FindStringSubmatch(doc.Text())
tokenRegex := regexp.MustCompile(`auctioneerToken\s?=\s?"([^"]+)";`).FindStringSubmatch(doc.Text())
if len(tokenRegex) != 2 {
return Auction{}, errors.New("failed to find auctioneer token")
}
auction.Token = tokenRegex[1]

// Find Planet / Moon resources JSON
planetMoonResources := regexp.MustCompile(`planetResources=([^;]+);`).FindStringSubmatch(doc.Text())
planetMoonResources := regexp.MustCompile(`planetResources\s?=\s?([^;]+);`).FindStringSubmatch(doc.Text())
if len(planetMoonResources) != 2 {
return Auction{}, errors.New("failed to find planetResources")
}
Expand Down
2 changes: 1 addition & 1 deletion ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ func (b *OGame) getAuction(celestialID CelestialID) (Auction, error) {
if celestialID != 0 {
payload.Set("cp", strconv.FormatInt(int64(celestialID), 10))
}
auctionHTML, err := b.postPageContent(url.Values{"page": {"traderOverview"}}, payload)
auctionHTML, err := b.postPageContent(url.Values{"page": {"ajax"}, "component": {"traderauctioneer"}}, payload)
if err != nil {
return Auction{}, err
}
Expand Down
6 changes: 6 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2897,6 +2897,12 @@ func TestFixAttackEvents(t *testing.T) {
assert.Equal(t, PlanetType, attacks[0].Destination.Type) // Did not change
}

func TestExtractAuction_ongoing2(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/v7.4/en/traderAuctioneer_ongoing.html")
res, _ := NewExtractorV6().ExtractAuction(pageHTMLBytes)
assert.Equal(t, int64(1800), res.Endtime)
}

func TestExtractAuction_ongoing(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/v7.1/en/traderOverview_ongoing.html")
res, _ := NewExtractorV6().ExtractAuction(pageHTMLBytes)
Expand Down
Loading

0 comments on commit 9b8fc2a

Please sign in to comment.