From 87a25d23193b3e8d4ab1a447c761e5ce11aa67e8 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 12 Feb 2020 00:21:24 +0100 Subject: [PATCH] Updated Interfaces Signed-off-by: Avior --- interfaces/Attack.ts | 66 ---------------------------------------- interfaces/Card.ts | 2 +- interfaces/Expansion.ts | 1 + interfaces/Illutrator.ts | 47 ---------------------------- interfaces/LangList.ts | 4 ++- interfaces/Set.ts | 2 ++ interfaces/Type.ts | 11 ++++--- 7 files changed, 13 insertions(+), 120 deletions(-) diff --git a/interfaces/Attack.ts b/interfaces/Attack.ts index f2f4db45b..d74edbb3b 100644 --- a/interfaces/Attack.ts +++ b/interfaces/Attack.ts @@ -1,6 +1,5 @@ import LangList from "./LangList"; import Type from "./Type"; -import { Page } from "puppeteer-core"; interface Attack { cost?: Array @@ -16,69 +15,4 @@ export interface LocalizedAttack { damage?: string|number } -namespace Attack { - export async function getAttacks(tab: Page, lang: string, existing?: Array): Promise> { - try { - const t = await tab.$$eval('.pokemon-abilities .ability', (els: Array) => { - const attacks: Array = [] - 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 = [] - for (const i in t) { - if (!t.hasOwnProperty(i)) continue - const att = t[i]; - let exist = existing && existing[i] || {} - - const cost: Array = [] - 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 diff --git a/interfaces/Card.ts b/interfaces/Card.ts index 997547a6b..f3a027aee 100644 --- a/interfaces/Card.ts +++ b/interfaces/Card.ts @@ -24,7 +24,7 @@ interface Card { type?: Array // ex for multiple https://api.pokemon.com/us/pokemon-tcg/pokemon-cards/ex-series/ex13/17/ image?: { - low: LangList, + low: LangList high?: LangList } diff --git a/interfaces/Expansion.ts b/interfaces/Expansion.ts index 9227dd612..cc3ff5ed5 100644 --- a/interfaces/Expansion.ts +++ b/interfaces/Expansion.ts @@ -3,4 +3,5 @@ import LangList from "./LangList"; export default interface Expansion { name: LangList | string code: string + sets?: Array } diff --git a/interfaces/Illutrator.ts b/interfaces/Illutrator.ts index 7a0c194c6..03ef67603 100644 --- a/interfaces/Illutrator.ts +++ b/interfaces/Illutrator.ts @@ -1,53 +1,6 @@ -import { Page } from "puppeteer-core" -import { promises as fs } from 'fs' - interface Illustrator { id: number name: string } -const file = "./generated/illustrators.json" - -let illustrators: Array = [] -namespace Illustrator { - export async function fetchIllustrators(): Promise { - 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 { - 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 { - return tab.$eval("h4.highlight a", (el:HTMLElement) => { - return el.innerText - }) - } - - export function save(): Promise { - return fs.writeFile(file, JSON.stringify(illustrators)) - } -} - export default Illustrator diff --git a/interfaces/LangList.ts b/interfaces/LangList.ts index d23b8169d..af4904862 100644 --- a/interfaces/LangList.ts +++ b/interfaces/LangList.ts @@ -5,8 +5,10 @@ type LangList = { it?: T } +export type Langs = "en" | "fr" | "es" | "it" + namespace LangList { - export function insert(from: LangList, el: any, lang: string) { + export function insert(from: LangList, el: any, lang: Langs) { if (typeof from !== "object") from = {} from[lang] = el return from diff --git a/interfaces/Set.ts b/interfaces/Set.ts index c70b6b502..4485702a5 100644 --- a/interfaces/Set.ts +++ b/interfaces/Set.ts @@ -19,6 +19,8 @@ export default interface Set { official: number } + format?: string + releaseDate?: string // date in format yyyy-mm-dd // api endpoint for scrapping diff --git a/interfaces/Type.ts b/interfaces/Type.ts index f43204440..93439d362 100644 --- a/interfaces/Type.ts +++ b/interfaces/Type.ts @@ -17,7 +17,7 @@ const en = [ "Darkness", "Dragon", "Fairy", - "Fightning", + "Fighting", "Fire", "Grass", "Lightning", @@ -27,7 +27,7 @@ const en = [ ] const fr = [ - "Sans Couleur", + "Incolore", "Obscurité", "Dragon", "Fée", @@ -78,12 +78,11 @@ namespace Type { return Type.FAIRY case "icon-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()) { case "plante": return Type.GRASS @@ -108,6 +107,7 @@ namespace Type { case "dragon": return Type.DRAGON } + throw new Error(`Error, type (${fr}) not found !`) } export function getFromSpanish(fr: string): Type { @@ -135,6 +135,7 @@ namespace Type { case "dragón": return Type.DRAGON } + throw new Error(`Error, type (${fr}) not found !`) } export function getFromEnglish(en: string): Type {