Populate templates in wiki cache (done)

This commit is contained in:
mtkennerly 2022-06-30 23:36:11 +08:00
parent ea7383e3a3
commit 0b47d3cbcd
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408
4 changed files with 8711 additions and 100 deletions

View file

@ -84,7 +84,7 @@ async function main() {
if (args.steam) {
await steamCache.refresh(
args.skipUntil,
args.irregularPathUntagged,
args.irregularPathUntagged ?? false,
args.limit ?? DEFAULT_GAME_LIMIT,
);
}

View file

@ -69,6 +69,7 @@ export class WikiGameCacheFile extends YamlFile<WikiGameCache> {
async refresh(skipUntil: string | undefined, limit: number): Promise<void> {
let i = 0;
let foundSkipUntil = false;
const client = makeApiClient();
for (const pageTitle of Object.keys(this.data).sort()) {
if (skipUntil && !foundSkipUntil) {
if (pageTitle === skipUntil) {
@ -79,7 +80,7 @@ export class WikiGameCacheFile extends YamlFile<WikiGameCache> {
}
// console.log(`Refreshing wiki page ${pageTitle}`);
await getGame(pageTitle, this.data);
await getGame(pageTitle, this.data, client);
i++;
if (limit > 0 && i >= limit) {
@ -582,9 +583,9 @@ export async function getRecentChanges(newest: Date, oldest: Date): Promise<Rece
/**
* https://www.pcgamingwiki.com/wiki/Template:Game_data
*/
export async function getGame(pageTitle: string, cache: WikiGameCache): Promise<[string, Game]> {
export async function getGame(pageTitle: string, cache: WikiGameCache, client: Wikiapi = null): Promise<[string, Game]> {
console.log(pageTitle);
const wiki = makeApiClient();
const wiki = client === null ? makeApiClient() : client;
let page = await wiki.page(pageTitle, { rvprop: "ids|content" });
if (page.missing !== undefined) {
// Couldn't find it by name, so try again by ID.