46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package main
|
|
|
|
import "os"
|
|
|
|
type Card struct {
|
|
AsciiName string `json:"asciiName"`
|
|
Name string `json:"name"`
|
|
Identifiers struct {
|
|
CardKingdomId string `json:"cardKingdomId"`
|
|
CardsphereId string `json:"cardsphereId"`
|
|
MCMId string `json:"mcmId"`
|
|
MCMMetaId string `json:"mcmMetaId"`
|
|
MTGOId string `json:"mtgoId"`
|
|
MultiverseId string `json:"multiverseId"`
|
|
ScryfallId string `json:"scryfallId"`
|
|
TCGPlayerProductId string `json:"tcgplayerProductId"`
|
|
} `json:"identifiers"`
|
|
Rarity string `json:"rarity"`
|
|
SetCode string `json:"setCode"`
|
|
CardType string `json:"type"`
|
|
Types []string `json:"types"`
|
|
UUID string `json:"uuid"`
|
|
}
|
|
|
|
type CardDB struct {
|
|
Data map[string]Card `json:"data"`
|
|
}
|
|
|
|
func loadCardInfos(identifierFile string) func() (map[string]Card, error) {
|
|
return func() (map[string]Card, error) {
|
|
// Check if identifiers file exists
|
|
_, err := os.Stat(identifierFile)
|
|
if os.IsNotExist(err) {
|
|
// Download identifiers file
|
|
err = downloadFile(identifierURL, identifierFile)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Read identifiers file
|
|
var cardDB CardDB
|
|
err = readJSONFile(identifierFile, &cardDB)
|
|
return cardDB.Data, err
|
|
}
|
|
}
|