mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-04-26 01:20:38 -05:00
Merge remote-tracking branch 'ticky/icalendar-schedules'
This commit is contained in:
commit
0275c83c22
|
|
@ -23,6 +23,7 @@
|
|||
"clean-webpack-plugin": "^0.1.16",
|
||||
"console-stamp": "^0.2.5",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"cozy-ical": "^1.1.22",
|
||||
"cron": "^1.2.1",
|
||||
"css-loader": "^0.28.4",
|
||||
"delay": "^2.0.0",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
const _ = require('lodash');
|
||||
const iCal = require('cozy-ical');
|
||||
const moment = require('moment-timezone');
|
||||
const Updater = require('./Updater');
|
||||
|
||||
class CoopSchedulesUpdater extends Updater {
|
||||
|
|
@ -38,6 +41,65 @@ class CoopSchedulesUpdater extends Updater {
|
|||
],
|
||||
});
|
||||
}
|
||||
|
||||
processData(data) {
|
||||
this.exportCalendar(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
exportCalendar({ details, schedules }) {
|
||||
// Create a calendar object
|
||||
const calendar = new iCal.VCalendar({
|
||||
title: this.constructor.name,
|
||||
organization: 'splatoon2.ink'
|
||||
});
|
||||
|
||||
// Set the calendar's native time zone to UTC
|
||||
calendar.add(new iCal.VTimezone({ timezone: 'Etc/UTC' }));
|
||||
|
||||
// Add detailed event information
|
||||
details.forEach((jsonEvent) => {
|
||||
const calendarEvent = new iCal.VEvent({
|
||||
summary: `Salmon Run on ${jsonEvent.stage.name}`,
|
||||
location: jsonEvent.stage.name,
|
||||
startDate: moment.tz(jsonEvent.start_time * 1000, 'UTC'),
|
||||
endDate: moment.tz(jsonEvent.end_time * 1000, 'UTC'),
|
||||
description: (
|
||||
'Supplied Weapons:\n • ' +
|
||||
jsonEvent.weapons.map((weapon) => weapon ? weapon.name : 'Random').join('\n • ')
|
||||
),
|
||||
stampDate: new Date(),
|
||||
uid: `coop-${jsonEvent.start_time}-${jsonEvent.end_time}`
|
||||
});
|
||||
|
||||
calendar.add(calendarEvent);
|
||||
});
|
||||
|
||||
// Add future event information
|
||||
schedules.forEach((jsonEvent) => {
|
||||
if (_.some(details, { start_time: jsonEvent.start_time, end_time: jsonEvent.end_time })) {
|
||||
return;
|
||||
}
|
||||
|
||||
const calendarEvent = new iCal.VEvent({
|
||||
summary: 'Salmon Run',
|
||||
startDate: moment.tz(jsonEvent.start_time * 1000, 'UTC'),
|
||||
endDate: moment.tz(jsonEvent.end_time * 1000, 'UTC'),
|
||||
stampDate: new Date(),
|
||||
uid: `coop-${jsonEvent.start_time}-${jsonEvent.end_time}`
|
||||
});
|
||||
|
||||
calendar.add(calendarEvent);
|
||||
});
|
||||
|
||||
// Save next to the .json file
|
||||
const filename = this.getFilename().replace(/\.json$/, '.ics');
|
||||
|
||||
const calendarString = calendar.toString();
|
||||
|
||||
// Write the calendar data to disk
|
||||
this.writeFile(filename, calendarString);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CoopSchedulesUpdater;
|
||||
|
|
|
|||
41
yarn.lock
41
yarn.lock
|
|
@ -1100,6 +1100,10 @@ bulma@^0.6.1:
|
|||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/bulma/-/bulma-0.6.1.tgz#5f21a77c0c06f7d80051c06628c23516081bd649"
|
||||
|
||||
byline@4.2.1:
|
||||
version "4.2.1"
|
||||
resolved "https://registry.yarnpkg.com/byline/-/byline-4.2.1.tgz#f74a66fa6d8feff88b2725e0b2b0cf830cdf3f86"
|
||||
|
||||
bytes@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
|
||||
|
|
@ -1494,6 +1498,17 @@ cosmiconfig@^2.1.0, cosmiconfig@^2.1.1:
|
|||
parse-json "^2.2.0"
|
||||
require-from-string "^1.1.0"
|
||||
|
||||
cozy-ical@^1.1.22:
|
||||
version "1.1.22"
|
||||
resolved "https://registry.yarnpkg.com/cozy-ical/-/cozy-ical-1.1.22.tgz#99206ffcd28dfca576e4889b9faa57b98cc1033a"
|
||||
dependencies:
|
||||
byline "4.2.1"
|
||||
extend "3.0.0"
|
||||
moment-timezone "0.5.3"
|
||||
printit "0.1.19"
|
||||
rrule "2.1.0"
|
||||
uuid "2.0.1"
|
||||
|
||||
create-ecdh@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d"
|
||||
|
|
@ -2248,6 +2263,10 @@ extend-shallow@^3.0.0:
|
|||
assign-symbols "^1.0.0"
|
||||
is-extendable "^1.0.1"
|
||||
|
||||
extend@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.0.tgz#5a474353b9f3353ddd8176dfd37b91c83a46f1d4"
|
||||
|
||||
extend@^3.0.0, extend@~3.0.0, extend@~3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
|
||||
|
|
@ -3874,12 +3893,22 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd
|
|||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
moment-timezone@0.5.3:
|
||||
version "0.5.3"
|
||||
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.3.tgz#34ba53bd719677975bee9d0e8ba799ad9373f082"
|
||||
dependencies:
|
||||
moment ">= 2.6.0"
|
||||
|
||||
moment-timezone@^0.5.13, moment-timezone@^0.5.x:
|
||||
version "0.5.14"
|
||||
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.14.tgz#4eb38ff9538b80108ba467a458f3ed4268ccfcb1"
|
||||
dependencies:
|
||||
moment ">= 2.9.0"
|
||||
|
||||
"moment@>= 2.6.0":
|
||||
version "2.22.0"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.0.tgz#7921ade01017dd45186e7fee5f424f0b8663a730"
|
||||
|
||||
"moment@>= 2.9.0":
|
||||
version "2.19.3"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.19.3.tgz#bdb99d270d6d7fda78cc0fbace855e27fe7da69f"
|
||||
|
|
@ -4755,6 +4784,10 @@ pretty-hrtime@^1.0.0:
|
|||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"
|
||||
|
||||
printit@0.1.19:
|
||||
version "0.1.19"
|
||||
resolved "https://registry.yarnpkg.com/printit/-/printit-0.1.19.tgz#b5ef5201d8077be411e483fb777659335d5626dc"
|
||||
|
||||
private@^0.1.6, private@^0.1.7, private@~0.1.5:
|
||||
version "0.1.8"
|
||||
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"
|
||||
|
|
@ -5270,6 +5303,10 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
|
|||
hash-base "^2.0.0"
|
||||
inherits "^2.0.1"
|
||||
|
||||
rrule@2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/rrule/-/rrule-2.1.0.tgz#6c5b3699e2e549f1dfc2609fe7ecf61c8ebad291"
|
||||
|
||||
run-async@^2.2.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
|
||||
|
|
@ -6135,6 +6172,10 @@ utils-merge@1.0.1:
|
|||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
|
||||
|
||||
uuid@2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.1.tgz#c2a30dedb3e535d72ccf82e343941a50ba8533ac"
|
||||
|
||||
uuid@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user