mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-07-11 23:26:06 -05:00
Retrieve Salmon Run schedule details from SplatNet
Thanks for adding this, Nintendo! ❤️
This commit is contained in:
parent
35eb01b2da
commit
dd073b6fb3
|
|
@ -4,10 +4,6 @@ NINTENDO_SESSION_ID=
|
|||
# (Optional) User agent string for SplatNet requests
|
||||
SPLATNET_USER_AGENT=
|
||||
|
||||
# Google Calendar ICS URL for Salmon Run schedules
|
||||
# Provided by: https://www.reddit.com/user/thejellydude
|
||||
SALMON_RUN_CALENDAR_ICS_URL=https://calendar.google.com/calendar/ical/7e5g474p0ng7vaejkg3mkomhks%40group.calendar.google.com/public/basic.ics
|
||||
|
||||
# (Optional) Google Analytics tracking ID
|
||||
GOOGLE_ANALYTICS_ID=
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
"he": "^1.1.1",
|
||||
"html-loader": "^0.5.0",
|
||||
"html-webpack-plugin": "^2.30.1",
|
||||
"ical.js": "^1.2.2",
|
||||
"json-stable-stringify": "^1.0.1",
|
||||
"make-runnable": "^1.3.6",
|
||||
"mkdirp": "^0.5.1",
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
require('./bootstrap');
|
||||
const axios = require('axios');
|
||||
const ical = require('ical.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function getEventsFromCalendar() {
|
||||
let response = await axios.get(process.env.SALMON_RUN_CALENDAR_ICS_URL);
|
||||
|
||||
let now = Math.trunc((new Date).getTime() / 1000);
|
||||
let schedules = [];
|
||||
|
||||
// Parse the ical format
|
||||
let jcalData = ical.parse(response.data);
|
||||
let comp = new ical.Component(jcalData);
|
||||
let vevents = comp.getAllSubcomponents('vevent');
|
||||
vevents.forEach(vevent => {
|
||||
let event = new ical.Event(vevent);
|
||||
|
||||
// We only care about Salmon Run events
|
||||
if (event.summary.toLowerCase().indexOf('salmon') === -1)
|
||||
return;
|
||||
|
||||
let start_time = event.startDate.toUnixTime();
|
||||
let end_time = event.endDate.toUnixTime();
|
||||
|
||||
// We only want events that haven't ended yet
|
||||
if (end_time < now)
|
||||
return;
|
||||
|
||||
schedules.push({ start_time, end_time, source: 'thejellydude' });
|
||||
});
|
||||
|
||||
return schedules;
|
||||
}
|
||||
|
||||
function getManualEvents() {
|
||||
let filename = path.resolve('manual-salmonrun.json');
|
||||
if (!fs.existsSync(filename))
|
||||
return [];
|
||||
return JSON.parse(fs.readFileSync(filename)).map(s => { if (!s.source) s.source = 'splatoon2.ink'; return s; });
|
||||
}
|
||||
|
||||
async function getSchedules() {
|
||||
let calendarEvents = await getEventsFromCalendar();
|
||||
let manualEvents = getManualEvents();
|
||||
|
||||
let keyedSchedules = {};
|
||||
|
||||
for (event of calendarEvents)
|
||||
keyedSchedules[event.start_time] = event;
|
||||
|
||||
for (event of manualEvents) {
|
||||
if (event.start_time in keyedSchedules)
|
||||
Object.assign(keyedSchedules[event.start_time], event);
|
||||
else
|
||||
keyedSchedules[event.start_time] = event;
|
||||
}
|
||||
|
||||
let schedules = Object.values(keyedSchedules);
|
||||
schedules.sort((a, b) => { return a.start_time - b.start_time });
|
||||
return { schedules };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSchedules,
|
||||
}
|
||||
|
|
@ -19,6 +19,11 @@ async function getSchedules() {
|
|||
return response.data;
|
||||
}
|
||||
|
||||
async function getCoopSchedules() {
|
||||
let response = await api.get('coop_schedules');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function getTimeline() {
|
||||
let response = await api.get('timeline');
|
||||
return response.data;
|
||||
|
|
@ -85,6 +90,7 @@ async function getImage(imagePath) {
|
|||
|
||||
module.exports = {
|
||||
getSchedules,
|
||||
getCoopSchedules,
|
||||
getTimeline,
|
||||
getNAFestivals,
|
||||
getEUFestivals,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ const fs = require('fs');
|
|||
const mkdirp = require('mkdirp');
|
||||
const splatnet = require('./splatnet');
|
||||
const retrieveWeapons = require('./retrieveWeapons');
|
||||
const salmoncalendar = require('./salmoncalendar');
|
||||
const raven = require('raven');
|
||||
|
||||
const dataPath = path.resolve('public/data');
|
||||
|
|
@ -34,6 +33,27 @@ async function updateSchedules() {
|
|||
}
|
||||
}
|
||||
|
||||
async function updateCoopSchedules() {
|
||||
let data = await handleRequest({
|
||||
title: 'co-op schedules',
|
||||
filename: `${dataPath}/coop-schedules.json`,
|
||||
request: splatnet.getCoopSchedules(),
|
||||
});
|
||||
|
||||
// Download images
|
||||
if (data) {
|
||||
for (let schedule of data.details) {
|
||||
await maybeDownloadImage(schedule.stage.image);
|
||||
|
||||
for (let weapon of schedule.weapons) {
|
||||
// Mystery weapons are null, so we have to make sure we don't attempt to download their images
|
||||
if (weapon)
|
||||
await maybeDownloadImage(weapon.image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function updateTimeline() {
|
||||
let data = await handleRequest({
|
||||
title: 'timeline',
|
||||
|
|
@ -154,21 +174,16 @@ async function updateWeapons() {
|
|||
await maybeDownloadImage(weapon.image);
|
||||
}
|
||||
|
||||
function updateSalmonRunCalendar() {
|
||||
return handleRequest({
|
||||
title: 'Salmon Run calendar',
|
||||
filename: `${dataPath}/salmonruncalendar.json`,
|
||||
request: salmoncalendar.getSchedules(),
|
||||
});
|
||||
}
|
||||
|
||||
async function updateAll() {
|
||||
await updateSchedules();
|
||||
await updateCoopSchedules();
|
||||
await updateTimeline();
|
||||
await updateFestivals();
|
||||
await updateMerchandises();
|
||||
await updateWeapons();
|
||||
await updateSalmonRunCalendar();
|
||||
|
||||
// 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.';
|
||||
}
|
||||
|
|
@ -235,11 +250,11 @@ function maybeDownloadImage(imagePath) {
|
|||
|
||||
module.exports = {
|
||||
updateSchedules,
|
||||
updateCoopSchedules,
|
||||
updateTimeline,
|
||||
updateFestivals,
|
||||
updateMerchandises,
|
||||
updateWeapons,
|
||||
updateSalmonRunCalendar,
|
||||
updateAll,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2555,10 +2555,6 @@ https-proxy-agent@^2.1.0:
|
|||
agent-base "^4.1.0"
|
||||
debug "^2.4.1"
|
||||
|
||||
ical.js@^1.2.2:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/ical.js/-/ical.js-1.2.2.tgz#59b517362a8f61dce0342fe67deb7c20dd119f6e"
|
||||
|
||||
iconv-lite@0.4.19:
|
||||
version "0.4.19"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user