Skip to content

Commit e0b0d09

Browse files
committed
fix: #855 Penny and Iono incorrectly marked as reprints
1 parent 23e9d25 commit e0b0d09

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

frontend/assets/cards.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25560,6 +25560,7 @@
2556025560
"alternate_versions": [
2556125561
332097,
2556225562
333317,
25563+
333377,
2556325564
742721,
2556425565
989829
2556525566
],
@@ -26229,6 +26230,7 @@
2622926230
"alternate_versions": [
2623026231
332097,
2623126232
333317,
26233+
333377,
2623226234
742721,
2623326235
989829
2623426236
],
@@ -41045,6 +41047,7 @@
4104541047
"alternate_versions": [
4104641048
528705,
4104741049
529797,
41050+
530177,
4104841051
990021
4104941052
],
4105041053
"artist": "Susumu Maeya",
@@ -41649,6 +41652,7 @@
4164941652
"alternate_versions": [
4165041653
528705,
4165141654
529797,
41655+
530177,
4165241656
990021
4165341657
],
4165441658
"artist": "Susumu Maeya",
@@ -66134,6 +66138,7 @@
6613466138
"alternate_versions": [
6613566139
332097,
6613666140
333317,
66141+
333377,
6613766142
742721,
6613866143
989829
6613966144
],
@@ -66162,6 +66167,7 @@
6616266167
"alternate_versions": [
6616366168
332097,
6616466169
333317,
66170+
333377,
6616566171
742721,
6616666172
989829
6616766173
],
@@ -93138,11 +93144,12 @@
9313893144
"alternate_versions": [
9313993145
332097,
9314093146
333317,
93147+
333377,
9314193148
742721,
9314293149
989829
9314393150
],
9314493151
"artist": "Sanosuke Sakuma",
93145-
"internal_id": 332097
93152+
"internal_id": 333377
9314693153
},
9314793154
{
9314893155
"expansion": "B2a",
@@ -93219,10 +93226,11 @@
9321993226
"alternate_versions": [
9322093227
528705,
9322193228
529797,
93229+
530177,
9322293230
990021
9322393231
],
9322493232
"artist": "yuu",
93225-
"internal_id": 528705
93233+
"internal_id": 530177
9322693234
},
9322793235
{
9322893236
"expansion": "B2a",
@@ -93694,6 +93702,7 @@
9369493702
"alternate_versions": [
9369593703
332097,
9369693704
333317,
93705+
333377,
9369793706
742721,
9369893707
989829
9369993708
],
@@ -93775,6 +93784,7 @@
9377593784
"alternate_versions": [
9377693785
528705,
9377793786
529797,
93787+
530177,
9377893788
990021
9377993789
],
9378093790
"artist": "yuu",

frontend/src/lib/CardsDB.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const expansions: Expansion[] = [
7777
packStructure: {
7878
containsShinies: false,
7979
containsBabies: false,
80+
containsLinkedCards: false,
8081
cardsPerPack: 5,
8182
},
8283
},
@@ -91,6 +92,7 @@ export const expansions: Expansion[] = [
9192
packStructure: {
9293
containsShinies: false,
9394
containsBabies: false,
95+
containsLinkedCards: true,
9496
cardsPerPack: 5,
9597
},
9698
},
@@ -109,6 +111,7 @@ export const expansions: Expansion[] = [
109111
packStructure: {
110112
containsShinies: false,
111113
containsBabies: false,
114+
containsLinkedCards: false,
112115
cardsPerPack: 5,
113116
},
114117
},
@@ -123,6 +126,7 @@ export const expansions: Expansion[] = [
123126
packStructure: {
124127
containsShinies: false,
125128
containsBabies: false,
129+
containsLinkedCards: false,
126130
cardsPerPack: 5,
127131
},
128132
},
@@ -137,6 +141,7 @@ export const expansions: Expansion[] = [
137141
packStructure: {
138142
containsShinies: true,
139143
containsBabies: false,
144+
containsLinkedCards: false,
140145
cardsPerPack: 5,
141146
},
142147
},
@@ -155,6 +160,7 @@ export const expansions: Expansion[] = [
155160
packStructure: {
156161
containsShinies: true,
157162
containsBabies: false,
163+
containsLinkedCards: false,
158164
cardsPerPack: 5,
159165
},
160166
},
@@ -169,6 +175,7 @@ export const expansions: Expansion[] = [
169175
packStructure: {
170176
containsShinies: true,
171177
containsBabies: false,
178+
containsLinkedCards: false,
172179
cardsPerPack: 5,
173180
},
174181
},
@@ -183,6 +190,7 @@ export const expansions: Expansion[] = [
183190
packStructure: {
184191
containsShinies: true,
185192
containsBabies: false,
193+
containsLinkedCards: false,
186194
cardsPerPack: 5,
187195
},
188196
},
@@ -201,6 +209,7 @@ export const expansions: Expansion[] = [
201209
packStructure: {
202210
containsShinies: true,
203211
containsBabies: true,
212+
containsLinkedCards: false,
204213
cardsPerPack: 5,
205214
},
206215
},
@@ -215,6 +224,7 @@ export const expansions: Expansion[] = [
215224
packStructure: {
216225
containsShinies: true,
217226
containsBabies: true,
227+
containsLinkedCards: false,
218228
cardsPerPack: 5,
219229
},
220230
},
@@ -229,6 +239,7 @@ export const expansions: Expansion[] = [
229239
packStructure: {
230240
containsShinies: true,
231241
containsBabies: false,
242+
containsLinkedCards: true,
232243
cardsPerPack: 4,
233244
},
234245
},
@@ -248,6 +259,7 @@ export const expansions: Expansion[] = [
248259
packStructure: {
249260
containsShinies: true,
250261
containsBabies: false,
262+
containsLinkedCards: false,
251263
cardsPerPack: 5,
252264
},
253265
},
@@ -262,6 +274,7 @@ export const expansions: Expansion[] = [
262274
packStructure: {
263275
containsShinies: true,
264276
containsBabies: false,
277+
containsLinkedCards: false,
265278
cardsPerPack: 5,
266279
},
267280
},
@@ -276,6 +289,7 @@ export const expansions: Expansion[] = [
276289
packStructure: {
277290
containsShinies: true,
278291
containsBabies: false,
292+
containsLinkedCards: false,
279293
cardsPerPack: 5,
280294
},
281295
},
@@ -290,6 +304,7 @@ export const expansions: Expansion[] = [
290304
packStructure: {
291305
containsShinies: true,
292306
containsBabies: false,
307+
containsLinkedCards: false,
293308
cardsPerPack: 5,
294309
},
295310
},

frontend/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface TradePartners {
9090
export interface PackStructure {
9191
containsShinies: boolean
9292
containsBabies: boolean
93+
containsLinkedCards: boolean
9394
cardsPerPack: 4 | 5
9495
}
9596

scripts/scraper.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CheerioAPI } from 'cheerio'
55
import * as cheerio from 'cheerio'
66
import fetch from 'node-fetch'
77
import { expansions as allExpansions } from '../frontend/src/lib/CardsDB'
8-
import { type Card, type CardType, cardTypes, type ExpansionId, type Rarity } from '../frontend/src/types'
8+
import { type Card, type CardType, cardTypes, type Expansion, type ExpansionId, type Rarity } from '../frontend/src/types'
99
import { encode } from './encoder'
1010

1111
const BASE_URL = 'https://pocket.limitlesstcg.com'
@@ -14,8 +14,6 @@ const targetDir = 'frontend/assets/'
1414
const imagesDir = 'frontend/public/images/en-US/'
1515
const imagesPath = '/images/en-US/'
1616

17-
const expansions = allExpansions.map((e) => e.id)
18-
1917
const packs = [
2018
'pikachupack',
2119
'charizardpack',
@@ -229,13 +227,13 @@ function urlToCardId(url: string): { expansion: string; cardNr: number; cardId:
229227
}
230228
}
231229

232-
async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string) {
230+
async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: Expansion) {
233231
const inPackId = Number.parseInt(cardUrl.split('/').pop(), 10)
234232
if (!inPackId) {
235233
throw new Error(`Faied to parse card id from url: ${cardUrl}`)
236234
}
237235

238-
const card_id = `${expansion}-${inPackId}`
236+
const card_id = `${expansion.id}-${inPackId}`
239237

240238
const imageUrl = $('img.card').attr('src')
241239
if (!imageUrl) {
@@ -313,7 +311,7 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
313311

314312
const raritySection = $('table.card-prints-versions tr.current')
315313
let rarity = (cardUrl.toString().includes('P-A') ? 'P' : raritySection.find('td:last-child').text().trim() || 'P') as Rarity
316-
for (const { rarity: rarityOverride, start, end } of rarityOverrides[expansion]) {
314+
for (const { rarity: rarityOverride, start, end } of rarityOverrides[expansion.id]) {
317315
if (start <= inPackId && inPackId <= end) {
318316
rarity = rarityOverride
319317
}
@@ -328,9 +326,10 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
328326

329327
const alternate_versions: string[] = []
330328
let linked = false
331-
let baseExpansion = expansion
329+
let baseExpansion = expansion.id
332330
let baseCardNr = inPackId
333331
let foundMyself = false
332+
const containsLinkedCards = expansion.packStructure?.containsLinkedCards
334333

335334
console.log('processing alternates for', card_id)
336335
$('table.card-prints-versions tr').each((_i, version) => {
@@ -348,8 +347,8 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
348347
// the alternate cards are only available up to EX card rarity (at least for now). And since limitless doesn't properly set shiny cards, we have to check it like this.
349348
// Be aware that for higher rarities this would not work, as there are different fullart versions of the same card with the same rarity, eg. A2a-82 and A2a-91.
350349
if (rarity.includes('◊') && alternate_card_rarity === rarity && !foundMyself && !linked) {
351-
baseExpansion = alternate_card_id ? urlToCardId(alternate_card_id).expansion : expansion
352-
baseCardNr = alternate_card_id ? urlToCardId(alternate_card_id).cardNr : inPackId
350+
baseExpansion = alternate_card_id ? (urlToCardId(alternate_card_id).expansion as ExpansionId) : expansion.id
351+
baseCardNr = alternate_card_id && containsLinkedCards ? urlToCardId(alternate_card_id).cardNr : inPackId
353352
linked = !!alternate_card_id // just for reference to double-check
354353
console.log('found alternate option', alternate_card_id, baseExpansion, baseCardNr, linked)
355354
}
@@ -358,9 +357,9 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
358357
// We consider it a foil card if we already linked it, but still find the same rarity in the same set before the current card.
359358
if (alternate_card_id && !foundMyself) {
360359
const alternateSetId = urlToCardId(alternate_card_id).expansion
361-
if (alternateSetId === expansion && alternate_card_rarity === rarity) {
360+
if (alternateSetId === expansion.id && alternate_card_rarity === rarity) {
362361
// same set, same rarity, means this one is an alternative art in the same set (can be foil), remove the link and treat like unique card.
363-
baseExpansion = expansion // foils don't have linked cards (at least not yet!)
362+
baseExpansion = expansion.id // foils don't have linked cards (at least not yet!)
364363
baseCardNr = inPackId
365364
linked = false
366365
console.log('disregarding alternate-->unique', baseExpansion, baseCardNr, linked)
@@ -379,7 +378,7 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
379378

380379
console.log('returning card info', card_id)
381380
return {
382-
expansion: expansion as ExpansionId,
381+
expansion: expansion.id as ExpansionId,
383382
card_id,
384383
image,
385384
hp,
@@ -402,11 +401,11 @@ async function extractCardInfo($: CheerioAPI, cardUrl: string, expansion: string
402401
}
403402
}
404403

405-
async function getCardDetails(cardUrl: string, expansionId: string) {
404+
async function getCardDetails(cardUrl: string, expansion: Expansion) {
406405
try {
407406
console.log(`Fetching details for ${cardUrl}...`)
408407
const $ = await fetchHTML(cardUrl)
409-
return await extractCardInfo($, cardUrl, expansionId)
408+
return await extractCardInfo($, cardUrl, expansion)
410409
} catch (error) {
411410
console.error(`Error fetching details for ${cardUrl}:`, error)
412411
return null // Return null or a default object to continue the process for other cards
@@ -430,9 +429,9 @@ async function getCardLinks(mainUrl: string) {
430429
const cards1: Awaited<ReturnType<typeof getCardDetails>>[] = []
431430

432431
async function scrapeCards() {
433-
for (const expansion of expansions) {
432+
for (const expansion of allExpansions) {
434433
try {
435-
const mainUrl = `${BASE_URL}/cards/${expansion}`
434+
const mainUrl = `${BASE_URL}/cards/${expansion.id}`
436435
const cardLinks = await getCardLinks(mainUrl)
437436
console.log(`Found ${cardLinks.length} card links.`)
438437

0 commit comments

Comments
 (0)