Skip digital-only cards, close insert statements

This commit is contained in:
The Magician 2024-05-21 15:52:26 +01:00
parent d21f1274a6
commit 411abd66f6
3 changed files with 33 additions and 11 deletions

View File

@ -48,11 +48,12 @@ func InsertOrUpdateSet(db *sql.DB, set types.Set) error {
}
func InsertCard(db *sql.DB, card types.Card) error {
query := `INSERT INTO CardPrinting
query := `INSERT IGNORE INTO CardPrinting
(Id, Name, SetCode, HasFoil, HasNonFoil, IsReserved, IsRacist, IsPromo, CollectorNumber, Language)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
insert, err := db.Prepare(query)
defer insert.Close()
if err != nil {
return err
}

View File

@ -23,6 +23,8 @@ const SET_ICON_FILE_EXTENSION string = ".svg"
const ALL_CARDS_CACHE_FILENAME = CACHE_DIR + "/all-cards.json"
const GAME_PAPER = "paper"
func check(err error) {
if err != nil {
log.Fatal(err)
@ -117,6 +119,12 @@ func cacheAllCardsFile(db *sql.DB, uri string, updatedAtTimestamp time.Time) err
func importCards(db *sql.DB, cards []types.Card) error {
for _, card := range cards {
// We're only interested in paper cards, so skip cards or printings of a card which
// aren't available in paper
if !isPaper(card) {
continue
}
err := operations.InsertCard(db, card)
if err != nil {
return err
@ -126,6 +134,18 @@ func importCards(db *sql.DB, cards []types.Card) error {
return nil
}
func isPaper(card types.Card) bool {
var paper bool = false
for _, game := range card.Games {
if game == GAME_PAPER {
paper = true
}
}
return paper
}
func main() {
log.Println("Connecting to database...")
db := database.GetDatabaseFromConfig("config.json")

View File

@ -4,6 +4,7 @@ type Card struct {
Id string `json:"id"` // GUID
Name string `json:"name"`
Set string `json:"set"`
Games []string `json:"games"`
Foil bool `json:"foil"`
NonFoil bool `json:"nonfoil"`
Reserved bool `json:"reserved"`