Returned StarCityGames support
This commit is contained in:
parent
de1187b96c
commit
7c6a6176dc
12 changed files with 133 additions and 72 deletions
|
|
@ -1,14 +1,50 @@
|
|||
package cardsinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
scryfall "github.com/BlueMonday/go-scryfall"
|
||||
"github.com/antchfx/htmlquery"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const scgDomain = "https://starcitygames.com"
|
||||
const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query=%v"
|
||||
|
||||
func GetPrices(name string) ([]CardPrice, error) {
|
||||
return GetPricesScg(name)
|
||||
}
|
||||
|
||||
func GetPricesScg(name string) ([]CardPrice, error) {
|
||||
escapedName := url.QueryEscape(name)
|
||||
searchUrl := fmt.Sprintf(scgSearchUrlTemplate, escapedName)
|
||||
node, err := htmlquery.LoadURL(searchUrl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cannot load url")
|
||||
}
|
||||
blocks := htmlquery.Find(node, "//div[@class=\"hawk-results-item\"]")
|
||||
var results []CardPrice
|
||||
for _, block := range blocks {
|
||||
price := &ScgCardPrice{}
|
||||
linkNode := htmlquery.FindOne(block, "//h2/a")
|
||||
for _, attr := range linkNode.Attr {
|
||||
if attr.Key == "href" {
|
||||
price.Link = scgDomain + attr.Val
|
||||
break
|
||||
}
|
||||
}
|
||||
editionNode := htmlquery.FindOne(block, "//p[@class=\"hawk-results-item__category\"]/a")
|
||||
price.Edition = editionNode.FirstChild.Data
|
||||
priceNode := htmlquery.FindOne(block, "//div[contains(concat(' ',normalize-space(@class),' '),' hawk-results-item__options-table-cell--price ')]")
|
||||
price.Price = priceNode.FirstChild.Data
|
||||
results = append(results, price)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func GetPricesTcg(name string) ([]CardPrice, error) {
|
||||
client, err := scryfall.NewClient()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot fetch prices")
|
||||
|
|
@ -24,7 +60,7 @@ func GetPrices(name string) ([]CardPrice, error) {
|
|||
if card.Prices.USD == "" && card.Prices.USDFoil == "" {
|
||||
continue
|
||||
}
|
||||
cardPrice := CardPrice {
|
||||
cardPrice := &TcgCardPrice {
|
||||
Edition: edition,
|
||||
Price: card.Prices.USD,
|
||||
PriceFoil: card.Prices.USDFoil,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue