Commit 7ac7f25a authored by nanahira's avatar nanahira

use cnocg as a ref

parent e899ad8e
Pipeline #4222 passed with stages
in 1 minute and 38 seconds
......@@ -9,6 +9,11 @@ export class CNOCGFetcher extends Base {
await fetcher.init();
return await fetcher.fetch();
}
static async fetchCodeOnce() {
const fetcher = new CNOCGFetcher({ name: "Temp NW Fetcher" });
await fetcher.init();
return await fetcher.fetchCode();
}
axiosInstance: AxiosInstance;
async init() {
await super.init();
......@@ -18,12 +23,13 @@ export class CNOCGFetcher extends Base {
})
})
}
async fetch(): Promise<Card[]> {
this.log.debug(`Started fetching from CNOCG source...`);
async fetchCode(): Promise<number[]> {
const allCardStrings: string[] = (await this.axiosInstance.get("https://api.tcgcardgame.com/api/cards/sc", {
responseType: "json"
})).data;
const allCards = allCardStrings.map(m => new Card(parseInt(m)));
return allCards;
return allCardStrings.map(m => parseInt(m));
}
async fetch(): Promise<Card[]> {
return (await this.fetchCode()).map(m => new Card(m));
}
}
import Base from "./base";
import { promises as fs } from "fs";
import { Card } from "./dbreader";
import { CNOCGFetcher } from "./cnocg";
export class DirectFetcher extends Base {
static async fetchOnce() {
const fetcher = new DirectFetcher({ name: "Temp Direct Fetcher", level: 'debug' });
const fetcher = new DirectFetcher({ name: "Temp Direct Fetcher", level: 'info' });
await fetcher.init();
return await fetcher.fetch();
}
......@@ -53,6 +54,8 @@ export class DirectFetcher extends Base {
}
}
async fetch(): Promise<Card[]> {
this.log.info(`Started fetching from CNOCG.`);
this.cardCodes = await CNOCGFetcher.fetchCodeOnce();
this.log.info(`Started reading from ydk cards.`);
const ydkFiles = await fs.readdir('./packs');
this.log.info(`${ydkFiles.length} packs found.`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment