Pokemon Code Scanner

I have collected Pokemon cards since they first set ink to cardboard. In fact some of my fondest childhood memories were visiting the Salisbury Mall ,rushing along the checkered tile floor, past the wafts of food court redolence and into the drab flourensence of your friendly local bookstore. I think it was Books A Million, but it could have been Borders side note I saw a Circuit City logo when googling for Borders and phew, takes me back. that red was gold.

One of the new additions to packs of ‘mon is a redeemable code. The code comes within the pack and is entered on a website to allow the user to redeem a digital copy of Pokemon cards. It is not directly 1:1 for all products, but for the most part if you purhcase physical Pack A you obtain digital Pack A- much like a DVD. These codes are fairly cumbersome to enter so I set about using technology to solve a process problem. It’s a pickle!

The first step in this process was to identify some site scraping tools. Most of my prior web scraping had been done with either Selenium or BealtifulSoup, but I have been on a Javascript kick lately and wanted to stick within the world that Eich built so after some Google-Fu I landed on Puppeteer. Just like some r/drawtheowl nonsense here is how I went from Step 1) decide to Step 3) test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');

(async () => {
const browser = await puppeteer.launch({ headless: false }); // launch browser
const page = await browser.newPage(); // open a new page

// navigate to the poke auth
await page.goto('https://redeem.tcg.pokemon.com');

// log in to your PTC account
await page.type('#email', 'EMAIL');
await page.type('#password', 'SECUREPASSWORD');
await page.click('input[type="submit"]');
await page.waitForNavigation();

// nav to redemption
await page.goto('https://redeem.tcg.pokemon.com/en-us/');

// promo code
await page.type('#code', 'YOUR_PROMO_CODE');
await page.click('button[type="submit"]');


await page.waitForSelector('.confirmation-message');

// extract the confirmation message
const content = await page.content();
const $ = cheerio.load(content);
const confirmationMessage = $('.confirmation-message').text();

console.log('Redemption Confirmation:', confirmationMessage);

// Close the browser
await browser.close();
})();

Overall it is straight forward, and strinkingly similar to Selenium style “create, wait, action, wait, action, repeat” application flow. I got tripped up initially with await page.click('input[type="submit"]'); and had 'button[type="submit"]'); but after a little debugging I resolved and rolled along. Now, the bigger problem? I can’t run this function past line 11 or 12 with the testing build of Chrome I have installed with Puppeteer because PoCo actually blocks it. TBD on resolution