From dd073b6fb3172e7651e2dfd6a33ebe2157d2c3b8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Nov 2017 09:27:27 -0800 Subject: [PATCH] Retrieve Salmon Run schedule details from SplatNet Thanks for adding this, Nintendo! :heart: --- .env.example | 4 --- package.json | 1 - src/updater/salmoncalendar.js | 67 ----------------------------------- src/updater/splatnet.js | 6 ++++ src/updater/update.js | 39 +++++++++++++------- yarn.lock | 4 --- 6 files changed, 33 insertions(+), 88 deletions(-) delete mode 100644 src/updater/salmoncalendar.js diff --git a/.env.example b/.env.example index b2eb635..c461d1b 100644 --- a/.env.example +++ b/.env.example @@ -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= diff --git a/package.json b/package.json index e5064c0..1ca9b26 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/updater/salmoncalendar.js b/src/updater/salmoncalendar.js deleted file mode 100644 index 39df758..0000000 --- a/src/updater/salmoncalendar.js +++ /dev/null @@ -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, -} diff --git a/src/updater/splatnet.js b/src/updater/splatnet.js index 70d9982..bbe2db4 100644 --- a/src/updater/splatnet.js +++ b/src/updater/splatnet.js @@ -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, diff --git a/src/updater/update.js b/src/updater/update.js index 1cef8cb..aa7fb70 100644 --- a/src/updater/update.js +++ b/src/updater/update.js @@ -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, } diff --git a/yarn.lock b/yarn.lock index 3cc3a2e..4103e50 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"