diff --git a/src/app/updater/updaters/FestivalsUpdater.js b/src/app/updater/updaters/FestivalsUpdater.js index 8a06d06..62dfff3 100644 --- a/src/app/updater/updaters/FestivalsUpdater.js +++ b/src/app/updater/updaters/FestivalsUpdater.js @@ -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(); diff --git a/src/app/updater/updaters/Updater.js b/src/app/updater/updaters/Updater.js index 643901c..6a8f06b 100644 --- a/src/app/updater/updaters/Updater.js +++ b/src/app/updater/updaters/Updater.js @@ -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 }) { diff --git a/src/common/splatnet.js b/src/common/splatnet.js index 769d76c..42d9357 100644 --- a/src/common/splatnet.js +++ b/src/common/splatnet.js @@ -71,6 +71,10 @@ class SplatNet { }; } + getFestivalRankings(id) { + return this.getResponse(`festivals/${id}/rankings`); + } + getMerchandises() { return this.getResponse('onlineshop/merchandises'); }