1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-07-23 09:29:49 +00:00
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-02-03 15:18:40 +01:00
commit 0d2a757cae
12077 changed files with 1123810 additions and 0 deletions

53
interfaces/Illutrator.ts Normal file
View File

@ -0,0 +1,53 @@
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<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