Retrieve Splatfest ranking data for each region

This isn't currently displayed in the UI anywhere, but it will be useful for other people who wish to use it.
This commit is contained in:
Matt Isenhower 2018-10-04 15:13:50 -07:00
parent 927012572d
commit 1dff97bd46
3 changed files with 32 additions and 4 deletions

View File

@ -4,8 +4,9 @@ const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const jsonpath = require('jsonpath');
const { readJson } = require('@/common/utilities');
const { readJson, writeJson } = require('@/common/utilities');
const { languages } = require('@/common/regions');
const SplatNet = require('@/common/splatnet');
class FestivalsUpdater extends Updater {
constructor(region) {
@ -39,7 +40,7 @@ class FestivalsUpdater extends Updater {
this.region = region;
}
processData(regionData) {
async processData(regionData) {
// Fix alpha/bravo images for the Chicken vs. Egg Splatfest.
// For some reason these got swapped out with images that have an opaque background
// even though they started out with transparent images.
@ -52,6 +53,25 @@ class FestivalsUpdater extends Updater {
"/images/festival/d93df77468714c6211e9377f39a559f4.png"
));
// Download result ranking data
let festivalIds = jsonpath.query(regionData, '$.results..festival_id');
for (let id of festivalIds) {
let filename = `${this.getOutputPath()}/festivals/${this.region.toLowerCase()}-${id}-rankings.json`;
// Have we already downloaded these rankings?
if (!fs.existsSync(filename)) {
let splatnet = new SplatNet(this.region);
this.info(`Retrieving rankings for festival ID ${id}`);
try {
let rankings = await this.handleRequest(splatnet.getFestivalRankings(id));
writeJson(filename, rankings);
}
catch (e) {
// Do nothing
}
}
}
// Load existing data since we only need to modify this region's data
let data = {};
let filename = this.getFilename();

View File

@ -51,13 +51,17 @@ class Updater {
this.info('Done.');
}
getOutputPath() {
return dataPath;
}
getFilename() {
return `${dataPath}/${this.options.filename}`;
return `${this.getOutputPath()}/${this.options.filename}`;
}
getCalendarFilename() {
if (this.options.calendarFilename)
return `${dataPath}/${this.options.calendarFilename}`;
return `${this.getOutputPath()}/${this.options.calendarFilename}`;
}
getData({ region, language }) {

View File

@ -71,6 +71,10 @@ class SplatNet {
};
}
getFestivalRankings(id) {
return this.getResponse(`festivals/${id}/rankings`);
}
getMerchandises() {
return this.getResponse('onlineshop/merchandises');
}