Feat: Add creating decks
This commit is contained in:
parent
7145906862
commit
aaa0bee853
26 changed files with 1279 additions and 180 deletions
|
@ -10,7 +10,7 @@ console.log('Status Code:', scryfallSets.status);
|
|||
const sets = await scryfallSets.json();
|
||||
|
||||
// Read the data from the exported fr_cards.json extracted from Scryfall Bulk Data
|
||||
const fileBytes = fs.readFileSync(import.meta.dirname + '/data/fr_cards.json')
|
||||
const fileBytes = fs.readFileSync(import.meta.dirname + '/data/default-cards-20241210100712.json')
|
||||
let scryfallData = JSON.parse(fileBytes)
|
||||
|
||||
// Connect to postgres database
|
||||
|
@ -23,6 +23,8 @@ const client = new Client({
|
|||
})
|
||||
await client.connect()
|
||||
|
||||
const two_faced_layouts = ["transform","modal_dfc","double_faced_token","reversible_card"]
|
||||
|
||||
try {
|
||||
const setRes = await client.query('SELECT id FROM set')
|
||||
const preUpdateSetRows = setRes.rows
|
||||
|
@ -47,15 +49,15 @@ try {
|
|||
});
|
||||
|
||||
// Define counter for logging
|
||||
let total_no_fr_name = 0
|
||||
let total_inserted = 0
|
||||
let total_skipped = 0
|
||||
|
||||
// For each card check if we need to upload it to the database
|
||||
for (const carte of scryfallData) {
|
||||
if(!preUpdateCardsIds.includes(carte.id)){
|
||||
let type = null
|
||||
const card_type = carte.type_line.toLowerCase()
|
||||
if(!preUpdateCardsIds.includes(carte.id) && carte.layout != "art_series"){
|
||||
let type = ""
|
||||
const layout = carte.layout
|
||||
const card_type = (carte.type_line == undefined) ? carte.card_faces[0].type_line.toLowerCase() : carte.type_line.toLowerCase()
|
||||
|
||||
if(card_type.includes("creature")){
|
||||
type = "creature"
|
||||
|
@ -73,27 +75,28 @@ try {
|
|||
type = "land"
|
||||
}
|
||||
|
||||
try {
|
||||
if(two_faced_layouts.includes(layout)) {
|
||||
const addingCardsQuery = await client.query('INSERT INTO carte(id, name, released_at, small_image, small_image_back, normal_image, normal_image_back, type_line, colors, set_id, rarity, cardmarket_uri, price, type, sanitized_name, set_code, layout) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)', [carte.id, carte.name, carte.released_at, carte.card_faces[0].image_uris.small, carte.card_faces[1].image_uris.small, carte.card_faces[0].image_uris.normal, carte.card_faces[0].image_uris.normal, carte.type_line, carte.color_identity, carte.set_id, carte.rarity, carte.purchase_uris?.cardmarket, carte.prices.eur, type, carte.name.replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase(), carte.set, layout])
|
||||
|
||||
} else {
|
||||
const addingCardsQuery = await client.query('INSERT INTO carte(id, name, released_at, small_image, normal_image, type_line, colors, set_id, rarity, cardmarket_uri, price, type, sanitized_name, set_code, layout) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)', [carte.id, carte.name, carte.released_at, carte.image_uris.small, carte.image_uris.normal, carte.type_line, carte.color_identity, carte.set_id, carte.rarity, carte.purchase_uris?.cardmarket, carte.prices.eur, type, carte.name.replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase(), carte.set, layout])
|
||||
|
||||
if(carte.printed_name == undefined) {
|
||||
// If the card doesn't have a french name, print it to the console and skip
|
||||
|
||||
//console.log("Erreur sur la carte : " + carte.name)
|
||||
//console.log("Scryfall URI : " + carte.scryfall_uri)
|
||||
//console.log("API URI : " + carte.uri)
|
||||
total_no_fr_name = total_no_fr_name + 1
|
||||
continue
|
||||
}
|
||||
total_inserted = total_inserted + 1
|
||||
} catch (err) {
|
||||
console.log(carte.uri)
|
||||
console.log(carte.layout)
|
||||
console.log(err)
|
||||
total_skipped = total_skipped + 1
|
||||
}
|
||||
|
||||
// Add the card to the database
|
||||
const addingCardsQuery = await client.query('INSERT INTO carte(id, name_en, name_fr, released_at, small_image, normal_image, mana_cost, cmc, type_line_en, type_line_fr, oracle_text_en, oracle_text_fr, power, toughness, colors, keywords, set_id, rarity, cardmarket_uri, type, sanitized_name) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)', [carte.id, carte.name, carte.printed_name, carte.released_at, carte.image_uris.small, carte.image_uris.normal, carte.mana_cost, carte.cmc, carte.type_line, carte.printed_type_line, carte.oracle_text, carte.printed_text, carte.power, carte.toughness, carte.color_identity, carte.keywords, carte.set_id, carte.rarity, carte.purchase_uris?.cardmarket, type, carte.name.replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase()])
|
||||
total_inserted = total_inserted + 1
|
||||
} else {
|
||||
total_skipped = total_skipped + 1
|
||||
}
|
||||
|
||||
}
|
||||
console.log("Un total de " + total_no_fr_name + " cartes n'ont pas de nom français.")
|
||||
console.log("Un total de " + total_inserted + " cartes ont été insérées.")
|
||||
console.log("Un total de " + total_skipped + " cartes ont été ignorées.")
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue