Fixed bug when card was on sale
This commit is contained in:
parent
a4dbd5a193
commit
563e6ddf01
1 changed files with 1 additions and 31 deletions
|
|
@ -1,11 +1,9 @@
|
|||
package cardsinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
scryfall "github.com/BlueMonday/go-scryfall"
|
||||
"github.com/antchfx/htmlquery"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
@ -46,7 +44,7 @@ func GetPricesScg(name string) ([]CardPrice, error) {
|
|||
if editionNode.FirstChild != nil {
|
||||
price.Edition = editionNode.FirstChild.Data
|
||||
}
|
||||
priceNode := htmlquery.FindOne(block, "//div[contains(concat(' ',normalize-space(@class),' '),' hawk-results-item__options-table-cell--price ')]")
|
||||
priceNode := htmlquery.FindOne(block, "//span[@class='hawk-old-price']|//div[contains(concat(' ',normalize-space(@class),' '),' hawk-results-item__options-table-cell--price ')]")
|
||||
if priceNode.FirstChild != nil {
|
||||
price.Price = priceNode.FirstChild.Data
|
||||
}
|
||||
|
|
@ -54,31 +52,3 @@ func GetPricesScg(name string) ([]CardPrice, error) {
|
|||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func GetPricesTcg(name string) ([]CardPrice, error) {
|
||||
client, err := scryfall.NewClient()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot fetch prices")
|
||||
}
|
||||
ctx := context.Background()
|
||||
opts := scryfall.SearchCardsOptions{
|
||||
Unique: scryfall.UniqueModePrints,
|
||||
}
|
||||
resp, err := client.SearchCards(ctx, fmt.Sprintf("!\"%v\"", name), opts)
|
||||
var prices []CardPrice
|
||||
for _, card := range resp.Cards {
|
||||
edition := card.SetName + " #" + card.CollectorNumber
|
||||
if card.Prices.USD == "" && card.Prices.USDFoil == "" {
|
||||
continue
|
||||
}
|
||||
cardPrice := &TcgCardPrice{
|
||||
Edition: edition,
|
||||
Price: card.Prices.USD,
|
||||
PriceFoil: card.Prices.USDFoil,
|
||||
Name: card.Name,
|
||||
Link: card.PurchaseURIs.TCGPlayer,
|
||||
}
|
||||
prices = append(prices, cardPrice)
|
||||
}
|
||||
return prices, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue