mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-09-12 04:25:13 -05:00
Track the time when a stage is first seen and first available
This will be used for tweets.
This commit is contained in:
@@ -45,6 +45,10 @@ class SplatNet {
|
||||
return this.getResponse('coop_schedules');
|
||||
}
|
||||
|
||||
getStages() {
|
||||
return this.getResponse('data/stages');
|
||||
}
|
||||
|
||||
getTimeline() {
|
||||
return this.getResponse('timeline');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require('./bootstrap');
|
||||
|
||||
const Updater = require('./updaters/Updater');
|
||||
const SchedulesUpdater = require('./updaters/SchedulesUpdater');
|
||||
const OriginalGearImageUpdater = require('./updaters/OriginalGearImageUpdater');
|
||||
const FestivalsUpdater = require('./updaters/FestivalsUpdater');
|
||||
const MerchandisesUpdater = require('./updaters/MerchandisesUpdater');
|
||||
@@ -10,15 +11,7 @@ const updaters = [
|
||||
new OriginalGearImageUpdater(),
|
||||
|
||||
// Schedules
|
||||
new Updater({
|
||||
name: 'Schedules',
|
||||
filename: 'schedules.json',
|
||||
request: (splatnet) => splatnet.getSchedules(),
|
||||
imagePaths: [
|
||||
'$..stage_a.image',
|
||||
'$..stage_b.image',
|
||||
],
|
||||
}),
|
||||
new SchedulesUpdater,
|
||||
|
||||
// Co-op Schedules
|
||||
new Updater({
|
||||
|
||||
61
src/updater/updaters/SchedulesUpdater.js
Normal file
61
src/updater/updaters/SchedulesUpdater.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const Updater = require('./Updater');
|
||||
const SplatNet = require('../splatnet');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { getTopOfCurrentHour, readJson } = require('../utilities');
|
||||
|
||||
const stagesPath = path.resolve('storage/stages.json');
|
||||
|
||||
class SchedulesUpdater extends Updater {
|
||||
constructor() {
|
||||
super({
|
||||
name: 'Schedules',
|
||||
filename: 'schedules.json',
|
||||
request: (splatnet) => splatnet.getSchedules(),
|
||||
imagePaths: [
|
||||
'$..stage_a.image',
|
||||
'$..stage_b.image',
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async processData(data) {
|
||||
// We need to track whether there are any new stages included with this schedule update
|
||||
|
||||
// If we don't have a "known stages" file, create it from the current list of stages
|
||||
if (!fs.existsSync(stagesPath)) {
|
||||
let splatnet = new SplatNet;
|
||||
let stageData = await splatnet.getStages();
|
||||
let stages = stageData.stages.map(s => Object.assign(s, { first_seen: -1, first_available: -1 }));
|
||||
this.writeFile(stagesPath, JSON.stringify(stages));
|
||||
}
|
||||
|
||||
// Load known stages
|
||||
let stages = readJson(stagesPath);
|
||||
|
||||
// Look for new stages (in Regular Battle)
|
||||
let sortedSchedules = data.regular.sort((a, b) => a.start_time - b.start_time);
|
||||
for (let schedule of sortedSchedules) {
|
||||
for (let stage of [schedule.stage_a, schedule.stage_b]) {
|
||||
// Have wee seen this stage before?
|
||||
let knownStage = stages.find(s => s.id == stage.id);
|
||||
|
||||
if (!knownStage) {
|
||||
// If we haven't seen the stage before, add it to the list with the current time
|
||||
// and the time the stage will be first available.
|
||||
stages.push(Object.assign({}, stage, {
|
||||
first_seen: getTopOfCurrentHour(),
|
||||
first_available: schedule.start_time,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the stages file
|
||||
this.writeFile(stagesPath, JSON.stringify(stages));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SchedulesUpdater;
|
||||
@@ -23,7 +23,7 @@ class Updater {
|
||||
data = this.filterRootKeys(data);
|
||||
|
||||
// Apply any other processing
|
||||
data = this.processData(data);
|
||||
data = await this.processData(data);
|
||||
|
||||
// Convert the data to a JSON string
|
||||
let dataString = JSON.stringify(data);
|
||||
|
||||
Reference in New Issue
Block a user