Skip to content

Commit

Permalink
tcgid4scryfall: Keep foil id separate if different from nonfoil
Browse files Browse the repository at this point in the history
Drop the old etched id which was hardly ever used.
  • Loading branch information
kodawah committed Jun 7, 2024
1 parent fd7934b commit 9371a62
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions cmd/tcgid4scryfall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ type Properties struct {
Number string
ScryfallId string

OldTcgId string
NewTcgId string

OldEtchedTcgId string
OldTcgId string
NewTcgId string
NewFoilTcgId string
NewEtchedTcgId string
}

Expand Down Expand Up @@ -208,17 +207,29 @@ func run() int {
}

newTcgId := cards[0].OriginalId
newFoilTcgId := ""
newEtchedTcgId := ""
oldTcgId := co.Identifiers["tcgplayerProductId"]

// If etched, there is always going to be a separate id,
// but the same is not guaranteed for every foil card
if co.Etched {
newEtchedTcgId = newTcgId
newTcgId = ""
oldTcgId = co.Identifiers["tcgplayerEtchedProductId"]
} else if co.Foil && len(co.Finishes) > 1 {
newFoilTcgId = newTcgId
newTcgId = ""
replace, found := co.Identifiers["tcgplayerFoilProductId"]
if found {
oldTcgId = replace
}
}

identifier := co.Identifiers["scryfallId"]
if (newTcgId != "" && oldTcgId != newTcgId) || (newEtchedTcgId != "" && oldTcgId != newEtchedTcgId) {
if (newTcgId != "" && oldTcgId != newTcgId) ||
(newEtchedTcgId != "" && oldTcgId != newEtchedTcgId) ||
(newFoilTcgId != "" && oldTcgId != newFoilTcgId) {
_, found := output[identifier]
if !found {
output[identifier] = &Properties{}
Expand All @@ -228,19 +239,20 @@ func run() int {
output[identifier].Number = co.Number
output[identifier].ScryfallId = identifier

output[identifier].OldTcgId = oldTcgId
if co.Etched {
output[identifier].OldEtchedTcgId = oldTcgId
output[identifier].NewEtchedTcgId = newEtchedTcgId
} else {
output[identifier].OldTcgId = oldTcgId
} else if co.Foil && len(co.Finishes) > 1 {
output[identifier].NewFoilTcgId = newFoilTcgId
} else if newTcgId != "" {
output[identifier].NewTcgId = newTcgId
}
}
}

csvWriter := csv.NewWriter(os.Stdout)
csvWriter.Write([]string{
"name", "set", "cn", "scryfall_id", "old_tcgplayer_id", "new_tcgplayer_id", "old_tcgplayer_etched_id", "new_tcgplayer_etched_id",
"name", "set", "cn", "scryfall_id", "old_tcgplayer_id", "new_tcgplayer_id", "new_tcgplayer_foil_id", "new_tcgplayer_etched_id",
})
fixes := 0
for _, props := range output {
Expand All @@ -252,7 +264,7 @@ func run() int {
props.ScryfallId,
props.OldTcgId,
props.NewTcgId,
props.OldEtchedTcgId,
props.NewFoilTcgId,
props.NewEtchedTcgId,
})
csvWriter.Flush()
Expand Down

0 comments on commit 9371a62

Please sign in to comment.