Skip digital-only cards, close insert statements
This commit is contained in:
parent
d21f1274a6
commit
411abd66f6
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package types
|
||||
|
||||
type Card struct {
|
||||
Id string `json:"id"` // GUID
|
||||
Name string `json:"name"`
|
||||
Set string `json:"set"`
|
||||
Foil bool `json:"foil"`
|
||||
NonFoil bool `json:"nonfoil"`
|
||||
Reserved bool `json:"reserved"`
|
||||
ContentWarning bool `json:"content_warning,omitempty"`
|
||||
Promo bool `json:"promo"`
|
||||
CollectorNumber string `json:"collector_number"`
|
||||
Language string `json:"lang"`
|
||||
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"`
|
||||
ContentWarning bool `json:"content_warning,omitempty"`
|
||||
Promo bool `json:"promo"`
|
||||
CollectorNumber string `json:"collector_number"`
|
||||
Language string `json:"lang"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue