tags: JavaScript Maria DB Python

Pokemon DB Part 1
Pokemon DB Part 2
Pokemon DB Part 3
Pokemon DB Part 4
Pokemon DB Part 5

Basics

We will be using TCGdex JavaScript SDK.
You can find further Infos here or here

Since this was and still is always a work in progress and my programming skills are nearly zero I apologize right away if you are feeling offended by this code

Lets start with the three pillars

  1. JavaScript to get the card data and extract it as a JSON file - we will be creating one file per card
  2. Python script to flatten the JSON and writing it in a MySql Database
  3. Web Site to display and search for all cards in our DB

I am sure you can streamline this an directly write the date in the SQLdb - but as already explained this was always a work in progress - the Idea for including a SQLdb came way later... I did not find the time to change the js code accordingly. And Python is so cool in flattening JSON files.


JavaScript

Setup, definitions and basic functions

I'll break it down as easy as possible

// import the SDK in commonJS
const TCGdex = require('@tcgdex/sdk').default
const fs = require('fs');
const readline = require('readline');

// Instantiate the SDK
const tcgdex = new TCGdex('de');

//Defining colors
const textColor = '\x1b[36m'; // Cyan color
const resetColor = '\x1b[0m'; // Reset color to default
const redColor = '\x1b[31m'; //Red Color
const greenColor = '\x1b[32m' //Green Color

The first lines of the code do the following

  • Import the required TCGdex JS SDK (const TCGdex = require('@tcgdex/sdk').default)
  • Import FileSystem (We will need to to write our Files later on
  • Import Readline to create console output
  • Define in which language we will be using TCGdex - in this case "de" for German
  • Set custom colors for later output
// Create an interface for reading from the console
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
    })
const question = (prompt) => new Promise((resolve) => {
    rl.question(prompt, resolve);
    })

//Question function
function askQuestion(question) {
  return new Promise(resolve => {
    rl.question(question, resolve);
  });
}

Now it gets a little bit abstract since we are NOT creating anything we are merely setting up. So bear with me!

The following lines setup and define our first function

const rl tells ReadLine to setup a interface with input and output - we will need this later to enter our card and set numbers
const question sets up the user prompt and returns a Promise (resolve)

Now to our function askQuestion(question)
Here we are utilizing everything we just set up

with this code nothing will happen - as already said we are just getting started!

Next functions will create variables for our CardNo and SetCount .... to be continued

Previous Post Next Post