Skip to content

Commit

Permalink
tcgplayer: Account for condition in links
Browse files Browse the repository at this point in the history
  • Loading branch information
kodawah committed Nov 25, 2023
1 parent 46518c4 commit 2e2b673
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sealedev/sealedev.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (ss *SealedEVScraper) runEV(prod productChan, channelOut chan respChan, pri
var link string
tcgID, _ := strconv.Atoi(product.Identifiers["tcgplayerProductId"])
if tcgID != 0 {
link = tcgplayer.TCGPlayerProductURL(tcgID, "", ss.Affiliate, "")
link = tcgplayer.TCGPlayerProductURL(tcgID, "", ss.Affiliate, "", "")
}

channelOut <- respChan{
Expand Down
2 changes: 1 addition & 1 deletion tcgplayer/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (tcg *TCGPlayerGeneric) processPage(channel chan<- genericChan, page int) e
"TCG Low", "TCG Market", "TCG Mid", "TCG Direct Low",
}

link := TCGPlayerProductURL(result.ProductId, result.SubTypeName, tcg.Affiliate, "")
link := TCGPlayerProductURL(result.ProductId, result.SubTypeName, tcg.Affiliate, "", "")

keys := []string{
fmt.Sprint(result.ProductId),
Expand Down
2 changes: 1 addition & 1 deletion tcgplayer/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (tcg *TCGPlayerIndex) processEntry(channel chan<- responseChan, reqs []inde
prices := []float64{
result.LowPrice, result.MarketPrice, result.MidPrice, result.DirectLowPrice,
}
link := TCGPlayerProductURL(result.ProductId, result.SubTypeName, tcg.Affiliate, co.Language)
link := TCGPlayerProductURL(result.ProductId, result.SubTypeName, tcg.Affiliate, "", co.Language)

for i := range availableIndexNames {
if prices[i] == 0 {
Expand Down
2 changes: 1 addition & 1 deletion tcgplayer/sealed.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (tcg *TCGPlayerSealed) processEntries(channel chan<- responseChan, reqs []i
}
}

link := TCGPlayerProductURL(result.ProductId, "", tcg.Affiliate, "")
link := TCGPlayerProductURL(result.ProductId, "", tcg.Affiliate, "", "")
out := responseChan{
cardId: uuid,
entry: mtgban.InventoryEntry{
Expand Down
2 changes: 1 addition & 1 deletion tcgplayer/seller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (tcg *TCGSellerInventory) processInventory(channel chan<- responseChan, res
continue
}

link := TCGPlayerProductURL(int(result.ProductID), listing.Printing, tcg.Affiliate, listing.Language)
link := TCGPlayerProductURL(int(result.ProductID), listing.Printing, tcg.Affiliate, listing.Condition, listing.Language)
out := responseChan{
cardId: cardId,
entry: mtgban.InventoryEntry{
Expand Down
2 changes: 1 addition & 1 deletion tcgplayer/tcgplayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (tcg *TCGPlayerMarket) processEntry(channel chan<- responseChan, reqs []mar
if req.Printing == "FOIL" {
printing = "Foil"
}
link := TCGPlayerProductURL(req.ProductId, printing, tcg.Affiliate, req.Language)
link := TCGPlayerProductURL(req.ProductId, printing, tcg.Affiliate, cond, req.Language)

for i := range availableMarketNames {
if prices[i] == 0 {
Expand Down
11 changes: 10 additions & 1 deletion tcgplayer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const baseProductURL = "https://www.tcgplayer.com/product/"

func TCGPlayerProductURL(productId int, printing, affiliate, language string) string {
func TCGPlayerProductURL(productId int, printing, affiliate, condition, language string) string {
u, err := url.Parse(baseProductURL + fmt.Sprint(productId))
if err != nil {
return ""
Expand All @@ -28,6 +28,15 @@ func TCGPlayerProductURL(productId int, printing, affiliate, language string) st
v.Set("utm_source", affiliate)
v.Set("partner", affiliate)
}
if condition != "" {
for full, short := range conditionMap {
if short == condition {
condition = full
break
}
}
v.Set("Condition", condition)
}
if language != "" {
language = mtgmatcher.Title(language)
switch language {
Expand Down

0 comments on commit 2e2b673

Please sign in to comment.