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 {
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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"`
|
||||||
|
Games []string `json:"games"`
|
||||||
Foil bool `json:"foil"`
|
Foil bool `json:"foil"`
|
||||||
NonFoil bool `json:"nonfoil"`
|
NonFoil bool `json:"nonfoil"`
|
||||||
Reserved bool `json:"reserved"`
|
Reserved bool `json:"reserved"`
|
||||||
|
|
Loading…
Reference in New Issue