From 5fa3c1110d3e9d00a939f2ac4c666d5493a0237e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 12 Nov 2017 11:05:08 -0800 Subject: [PATCH] Remove weapon update code This was used for the Salmon Run admin dialog, but that's no longer needed since Salmon Run schedules are now available via SplatNet. Removing this for now since I don't really need the weapons database anywhere now and since I'm going to refactor the SplatNet updater. --- src/updater/retrieveWeapons.js | 58 ---------------------------------- src/updater/update.js | 41 ------------------------ 2 files changed, 99 deletions(-) delete mode 100644 src/updater/retrieveWeapons.js diff --git a/src/updater/retrieveWeapons.js b/src/updater/retrieveWeapons.js deleted file mode 100644 index cfcafa9..0000000 --- a/src/updater/retrieveWeapons.js +++ /dev/null @@ -1,58 +0,0 @@ -const delay = require('delay'); -const splatnet = require('./splatnet'); - -/** - * The SplatNet 2 API doesn't currently provide a way to retrieve weapon data directly. - * There are, however, several API endpoints that provide weapon data along with their results. - * - * This function retrieves recent league match rankings and parses weapon data from those results. - * This data is provided in blocks of 2 hours. Generally, retrieving the last 2-3 blocks of data - * is enough to retrieve all currently-available weapons. - */ - -module.exports = async function retrieveWeapons(iterations = 1, useDelay = true) { - // Start from "now" and work backwards - let date = new Date(); - date.setUTCMinutes(0); - date.setUTCSeconds(0); - - // Give an extra hour delay to allow time for results to come in (and to prevent 404s) - date.setUTCHours(date.getUTCHours() - 1); - - // Hours must be in multiples of 2 - if (date.getUTCHours() % 2 == 1) - date.setUTCHours(date.getUTCHours() - 1); - - let weapons = {}; - - // We'll retrieve up to the number of iterations specified of result data. - // For example: 2017-09-01 06:00, then 2017-09-01 04:00, then 2017-09-01 02:00, etc. - - for (let i = 0; i < iterations; i++) { - // Start with the previous time block (2 hours ago) even on the first run - date.setUTCHours(date.getUTCHours() - 2); - - let year = date.getUTCFullYear(); - let month = date.getUTCMonth() + 1; - let day = date.getUTCDate(); - let hour = date.getUTCHours(); - - // Get both team and pair rankings - console.info(`Getting league rankings for ${year}-${month}-${day} hour ${hour}...`); - let teamRanking = await splatnet.getLeagueMatchRanking(year, month, day, hour, 'T'); - let pairRanking = await splatnet.getLeagueMatchRanking(year, month, day, hour, 'P'); - - // Process the results - for (let ranking of [teamRanking, pairRanking]) { - for (rankInfo of ranking.rankings) { - for (player of rankInfo.tag_members) - weapons[player.weapon.id] = player.weapon; - } - } - - if (useDelay && (i + 1) < iterations) - await delay(500); - } - - return weapons; -} diff --git a/src/updater/update.js b/src/updater/update.js index 564bb08..ccf97db 100644 --- a/src/updater/update.js +++ b/src/updater/update.js @@ -3,7 +3,6 @@ const path = require('path'); const fs = require('fs'); const mkdirp = require('mkdirp'); const splatnet = require('./splatnet'); -const retrieveWeapons = require('./retrieveWeapons'); const raven = require('raven'); const dataPath = path.resolve('public/data'); @@ -139,51 +138,12 @@ async function updateMerchandises() { } } -async function updateWeapons() { - // This one is handled a little differently since we need to add to the existing data - // instead of just overwriting it. We don't have a way to retrieve a complete set - // of weapon data, so we have to make sure not to lose any weapons we already know about. - - let filename = `${dataPath}/weapons.json`; - - // Look for weapons used over the past 24 hours if we don't have an existing list of weapons. - let iterations = 12; - let weapons = {}; - - if (fs.existsSync(filename)) { - weapons = JSON.parse(fs.readFileSync(filename)); - - // If we already have a weapons file, only retrieve the most recent results - iterations = 1; - } - - // We're now ready to update the weapons - await handleRequest({ - title: 'weapons', - filename, - request: retrieveWeapons(iterations), - transformer: responseData => { - // Add the new weapons to the existing list of weapons - return Object.assign(weapons, responseData); - }, - }); - - // Get weapon images - for (let weapon of Object.values(weapons)) - await maybeDownloadImage(weapon.image); -} - async function updateAll() { await updateSchedules(); await updateCoopSchedules(); await updateTimeline(); await updateFestivals(); await updateMerchandises(); - - // We don't need to maintain the weapons database anymore since Salmon Run data is now available via SplatNet. - // Leaving this here for now though just in case we need it in the future. - // await updateWeapons(); - return 'Done.'; } @@ -253,7 +213,6 @@ module.exports = { updateTimeline, updateFestivals, updateMerchandises, - updateWeapons, updateAll, }