Fixed bug when card was on sale

This commit is contained in:
Artyom Belousov 2021-02-03 20:55:20 +03:00
parent a4dbd5a193
commit 563e6ddf01

View file

@ -1,11 +1,9 @@
package cardsinfo package cardsinfo
import ( import (
"context"
"fmt" "fmt"
"net/url" "net/url"
scryfall "github.com/BlueMonday/go-scryfall"
"github.com/antchfx/htmlquery" "github.com/antchfx/htmlquery"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -46,7 +44,7 @@ func GetPricesScg(name string) ([]CardPrice, error) {
if editionNode.FirstChild != nil { if editionNode.FirstChild != nil {
price.Edition = editionNode.FirstChild.Data 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 { if priceNode.FirstChild != nil {
price.Price = priceNode.FirstChild.Data price.Price = priceNode.FirstChild.Data
} }
@ -54,31 +52,3 @@ func GetPricesScg(name string) ([]CardPrice, error) {
} }
return results, nil 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
}