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 { 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) (Id, Name, SetCode, HasFoil, HasNonFoil, IsReserved, IsRacist, IsPromo, CollectorNumber, Language)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
insert, err := db.Prepare(query) insert, err := db.Prepare(query)
defer insert.Close()
if err != nil { if err != nil {
return err 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 ALL_CARDS_CACHE_FILENAME = CACHE_DIR + "/all-cards.json"
const GAME_PAPER = "paper"
func check(err error) { func check(err error) {
if err != nil { if err != nil {
log.Fatal(err) 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 { func importCards(db *sql.DB, cards []types.Card) error {
for _, card := range cards { 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) err := operations.InsertCard(db, card)
if err != nil { if err != nil {
return err return err
@ -126,6 +134,18 @@ func importCards(db *sql.DB, cards []types.Card) error {
return nil 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() { func main() {
log.Println("Connecting to database...") log.Println("Connecting to database...")
db := database.GetDatabaseFromConfig("config.json") db := database.GetDatabaseFromConfig("config.json")

View File

@ -1,14 +1,15 @@
package types package types
type Card struct { type Card struct {
Id string `json:"id"` // GUID Id string `json:"id"` // GUID
Name string `json:"name"` Name string `json:"name"`
Set string `json:"set"` Set string `json:"set"`
Foil bool `json:"foil"` Games []string `json:"games"`
NonFoil bool `json:"nonfoil"` Foil bool `json:"foil"`
Reserved bool `json:"reserved"` NonFoil bool `json:"nonfoil"`
ContentWarning bool `json:"content_warning,omitempty"` Reserved bool `json:"reserved"`
Promo bool `json:"promo"` ContentWarning bool `json:"content_warning,omitempty"`
CollectorNumber string `json:"collector_number"` Promo bool `json:"promo"`
Language string `json:"lang"` CollectorNumber string `json:"collector_number"`
Language string `json:"lang"`
} }