mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-04-23 03:12:10 +00:00
Updated Interfaces
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
1cd9af0ddb
commit
87a25d2319
@ -1,6 +1,5 @@
|
|||||||
import LangList from "./LangList";
|
import LangList from "./LangList";
|
||||||
import Type from "./Type";
|
import Type from "./Type";
|
||||||
import { Page } from "puppeteer-core";
|
|
||||||
|
|
||||||
interface Attack {
|
interface Attack {
|
||||||
cost?: Array<Type>
|
cost?: Array<Type>
|
||||||
@ -16,69 +15,4 @@ export interface LocalizedAttack {
|
|||||||
damage?: string|number
|
damage?: string|number
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Attack {
|
|
||||||
export async function getAttacks(tab: Page, lang: string, existing?: Array<Attack>): Promise<Array<Attack>> {
|
|
||||||
try {
|
|
||||||
const t = await tab.$$eval('.pokemon-abilities .ability', (els: Array<HTMLElement>) => {
|
|
||||||
const attacks: Array<LocalizedAttack> = []
|
|
||||||
const r = /^[0-9]+$/
|
|
||||||
for (const e of els) {
|
|
||||||
if (e.childElementCount < 2) continue
|
|
||||||
const cost = []
|
|
||||||
e.querySelectorAll("ul.left li i").forEach(el => {
|
|
||||||
el.classList.remove("energy")
|
|
||||||
cost.push(el.classList.item(0))
|
|
||||||
})
|
|
||||||
const txt = e.querySelector("pre")?.innerText
|
|
||||||
const power = (e.querySelector("span.right") as HTMLElement)?.innerText
|
|
||||||
attacks.push({
|
|
||||||
cost,
|
|
||||||
name: e.querySelector("h4")?.innerText,
|
|
||||||
text: txt ? txt : undefined,
|
|
||||||
damage: r.test(power) ? parseInt(power) : power
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return attacks
|
|
||||||
})
|
|
||||||
const atts: Array<Attack> = []
|
|
||||||
for (const i in t) {
|
|
||||||
if (!t.hasOwnProperty(i)) continue
|
|
||||||
const att = t[i];
|
|
||||||
let exist = existing && existing[i] || {}
|
|
||||||
|
|
||||||
const cost: Array<Type> = []
|
|
||||||
for (const e of att.cost) {
|
|
||||||
if (typeof e === "number") {
|
|
||||||
cost.push(e)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (e === "icon-free") continue
|
|
||||||
try {
|
|
||||||
cost.push(
|
|
||||||
Type.getFromClass(e)
|
|
||||||
)
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
console.log(tab.url())
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const taa: Attack = {
|
|
||||||
name: LangList.insert(exist["name"], att.name, lang)
|
|
||||||
}
|
|
||||||
if (att.text) taa.text = LangList.insert(exist["text"], att.text, lang)
|
|
||||||
if (att.damage) taa.damage = att.damage
|
|
||||||
if (att.cost) taa.cost = cost
|
|
||||||
|
|
||||||
atts.push(taa)
|
|
||||||
}
|
|
||||||
return atts
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Attack
|
export default Attack
|
||||||
|
@ -24,7 +24,7 @@ interface Card {
|
|||||||
type?: Array<Type> // ex for multiple https://api.pokemon.com/us/pokemon-tcg/pokemon-cards/ex-series/ex13/17/
|
type?: Array<Type> // ex for multiple https://api.pokemon.com/us/pokemon-tcg/pokemon-cards/ex-series/ex13/17/
|
||||||
|
|
||||||
image?: {
|
image?: {
|
||||||
low: LangList<string>,
|
low: LangList<string>
|
||||||
high?: LangList<string>
|
high?: LangList<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,4 +3,5 @@ import LangList from "./LangList";
|
|||||||
export default interface Expansion {
|
export default interface Expansion {
|
||||||
name: LangList<string> | string
|
name: LangList<string> | string
|
||||||
code: string
|
code: string
|
||||||
|
sets?: Array<string>
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,6 @@
|
|||||||
import { Page } from "puppeteer-core"
|
|
||||||
import { promises as fs } from 'fs'
|
|
||||||
|
|
||||||
interface Illustrator {
|
interface Illustrator {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = "./generated/illustrators.json"
|
|
||||||
|
|
||||||
let illustrators: Array<string> = []
|
|
||||||
namespace Illustrator {
|
|
||||||
export async function fetchIllustrators(): Promise<void> {
|
|
||||||
const illus = await fs.readFile(file)
|
|
||||||
illustrators = JSON.parse(illus.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
export function processIllustrator(str: string): Illustrator {
|
|
||||||
if (!illustrators.includes(str)) {
|
|
||||||
illustrators.push(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: illustrators.indexOf(str),
|
|
||||||
name: str
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getIllustrator(tab: Page): Promise<Illustrator> {
|
|
||||||
const illustrator = await getIllustratorFromPage(tab)
|
|
||||||
if (!illustrators.includes(illustrator)) {
|
|
||||||
illustrators.push(illustrator)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: illustrators.indexOf(illustrator),
|
|
||||||
name: illustrator
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getIllustratorFromPage(tab: Page): Promise<string> {
|
|
||||||
return tab.$eval("h4.highlight a", (el:HTMLElement) => {
|
|
||||||
return el.innerText
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function save(): Promise<void> {
|
|
||||||
return fs.writeFile(file, JSON.stringify(illustrators))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Illustrator
|
export default Illustrator
|
||||||
|
@ -5,8 +5,10 @@ type LangList<T> = {
|
|||||||
it?: T
|
it?: T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Langs = "en" | "fr" | "es" | "it"
|
||||||
|
|
||||||
namespace LangList {
|
namespace LangList {
|
||||||
export function insert(from: LangList<any>, el: any, lang: string) {
|
export function insert(from: LangList<any>, el: any, lang: Langs) {
|
||||||
if (typeof from !== "object") from = {}
|
if (typeof from !== "object") from = {}
|
||||||
from[lang] = el
|
from[lang] = el
|
||||||
return from
|
return from
|
||||||
|
@ -19,6 +19,8 @@ export default interface Set {
|
|||||||
official: number
|
official: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format?: string
|
||||||
|
|
||||||
releaseDate?: string // date in format yyyy-mm-dd
|
releaseDate?: string // date in format yyyy-mm-dd
|
||||||
|
|
||||||
// api endpoint for scrapping
|
// api endpoint for scrapping
|
||||||
|
@ -17,7 +17,7 @@ const en = [
|
|||||||
"Darkness",
|
"Darkness",
|
||||||
"Dragon",
|
"Dragon",
|
||||||
"Fairy",
|
"Fairy",
|
||||||
"Fightning",
|
"Fighting",
|
||||||
"Fire",
|
"Fire",
|
||||||
"Grass",
|
"Grass",
|
||||||
"Lightning",
|
"Lightning",
|
||||||
@ -27,7 +27,7 @@ const en = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const fr = [
|
const fr = [
|
||||||
"Sans Couleur",
|
"Incolore",
|
||||||
"Obscurité",
|
"Obscurité",
|
||||||
"Dragon",
|
"Dragon",
|
||||||
"Fée",
|
"Fée",
|
||||||
@ -78,12 +78,11 @@ namespace Type {
|
|||||||
return Type.FAIRY
|
return Type.FAIRY
|
||||||
case "icon-dragon":
|
case "icon-dragon":
|
||||||
return Type.DRAGON
|
return Type.DRAGON
|
||||||
default:
|
}
|
||||||
throw new Error(`Error, type (${classe}) not found !`)
|
throw new Error(`Error, type (${classe}) not found !`)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function getFromFrench(fr: string): Type {
|
export function getFromFrench(fr: string): Type|undefined {
|
||||||
switch (fr.toLowerCase()) {
|
switch (fr.toLowerCase()) {
|
||||||
case "plante":
|
case "plante":
|
||||||
return Type.GRASS
|
return Type.GRASS
|
||||||
@ -108,6 +107,7 @@ namespace Type {
|
|||||||
case "dragon":
|
case "dragon":
|
||||||
return Type.DRAGON
|
return Type.DRAGON
|
||||||
}
|
}
|
||||||
|
throw new Error(`Error, type (${fr}) not found !`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFromSpanish(fr: string): Type {
|
export function getFromSpanish(fr: string): Type {
|
||||||
@ -135,6 +135,7 @@ namespace Type {
|
|||||||
case "dragón":
|
case "dragón":
|
||||||
return Type.DRAGON
|
return Type.DRAGON
|
||||||
}
|
}
|
||||||
|
throw new Error(`Error, type (${fr}) not found !`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFromEnglish(en: string): Type {
|
export function getFromEnglish(en: string): Type {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user