Add festival data updater

This commit is contained in:
Matt Isenhower
2022-09-16 12:51:23 -07:00
parent 42520b20f5
commit 866509a4d8
4 changed files with 48 additions and 3 deletions

View File

@@ -1,12 +1,17 @@
import GearUpdater from "./updaters/GearUpdater.mjs";
import StageScheduleUpdater from "./updaters/StageScheduleUpdater.mjs";
import CoopUpdater from "./updaters/CoopUpdater.mjs";
import FestivalUpdater from "./updaters/FestivalUpdater.mjs";
function updaters() {
return [
new StageScheduleUpdater,
new GearUpdater,
new CoopUpdater,
new FestivalUpdater('NA'),
new FestivalUpdater('EU'),
new FestivalUpdater('JP'),
new FestivalUpdater('AP'),
];
}

View File

@@ -20,9 +20,13 @@ export default class DataUpdater
this.imageProcessor = new ImageProcessor;
}
get region() {
return this.splatnet.nsoClient.region;
}
/** @type {Console} */
get console() {
this._console ??= prefixedConsole('Updater', this.splatnet.nsoClient.region, this.name);
this._console ??= prefixedConsole('Updater', this.region, this.name);
return this._console;
}
@@ -78,7 +82,7 @@ export default class DataUpdater
// File handling
async saveData(data) {
let s = this.formatDataForWrite(data);
let s = await this.formatDataForWrite(data);
await this.writeFile(this.getPath(this.filename), s);
@@ -91,7 +95,7 @@ export default class DataUpdater
return `${this.outputDirectory}/${filename}.json`;
}
formatDataForWrite(data) {
async formatDataForWrite(data) {
// If we're running in debug mode, format the JSON output so it's easier to read
let debug = !!process.env.DEBUG;
let space = debug ? 2 : undefined;

View File

@@ -0,0 +1,32 @@
import fs from 'fs/promises';
import DataUpdater from "./DataUpdater.mjs";
export default class FestivalUpdater extends DataUpdater
{
name = 'Festivals';
filename = 'festivals';
imagePaths = [
'$..image.url',
];
getData() {
return this.splatnet.getFestRecordData();
}
async formatDataForWrite(data) {
// Combine this region's data with the other regions' data.
let result = null;
try {
result = await fs.readFile(this.getPath(this.filename));
} catch (e) {
//
}
result = result ? JSON.parse(result) : {};
result[this.region] = data;
return super.formatDataForWrite(result);
}
}

View File

@@ -124,4 +124,8 @@ export default class SplatNet3Client
getCoopHistoryData() {
return this.getGraphQLPersistedQuery(1, '817618ce39bcf5570f52a97d73301b30');
}
getFestRecordData() {
return this.getGraphQLPersistedQuery(1, '44c76790b68ca0f3da87f2a3452de986');
}
}