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 { ...@@ -9,6 +9,11 @@ export class CNOCGFetcher extends Base {
await fetcher.init(); await fetcher.init();
return await fetcher.fetch(); return await fetcher.fetch();
} }
static async fetchCodeOnce() {
const fetcher = new CNOCGFetcher({ name: "Temp NW Fetcher" });
await fetcher.init();
return await fetcher.fetchCode();
}
axiosInstance: AxiosInstance; axiosInstance: AxiosInstance;
async init() { async init() {
await super.init(); await super.init();
...@@ -18,12 +23,13 @@ export class CNOCGFetcher extends Base { ...@@ -18,12 +23,13 @@ export class CNOCGFetcher extends Base {
}) })
}) })
} }
async fetch(): Promise<Card[]> { async fetchCode(): Promise<number[]> {
this.log.debug(`Started fetching from CNOCG source...`);
const allCardStrings: string[] = (await this.axiosInstance.get("https://api.tcgcardgame.com/api/cards/sc", { const allCardStrings: string[] = (await this.axiosInstance.get("https://api.tcgcardgame.com/api/cards/sc", {
responseType: "json" responseType: "json"
})).data; })).data;
const allCards = allCardStrings.map(m => new Card(parseInt(m))); return allCardStrings.map(m => parseInt(m));
return allCards; }
async fetch(): Promise<Card[]> {
return (await this.fetchCode()).map(m => new Card(m));
} }
} }
import Base from "./base"; import Base from "./base";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import { Card } from "./dbreader"; import { Card } from "./dbreader";
import { CNOCGFetcher } from "./cnocg";
export class DirectFetcher extends Base { export class DirectFetcher extends Base {
static async fetchOnce() { 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(); await fetcher.init();
return await fetcher.fetch(); return await fetcher.fetch();
} }
...@@ -53,6 +54,8 @@ export class DirectFetcher extends Base { ...@@ -53,6 +54,8 @@ export class DirectFetcher extends Base {
} }
} }
async fetch(): Promise<Card[]> { async fetch(): Promise<Card[]> {
this.log.info(`Started fetching from CNOCG.`);
this.cardCodes = await CNOCGFetcher.fetchCodeOnce();
this.log.info(`Started reading from ydk cards.`); this.log.info(`Started reading from ydk cards.`);
const ydkFiles = await fs.readdir('./packs'); const ydkFiles = await fs.readdir('./packs');
this.log.info(`${ydkFiles.length} packs found.`); 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