From fae86d6f9fc259f76c20b3611bc0233cee75c1c9 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 27 May 2023 17:07:52 +0200 Subject: [PATCH] :tada: Generate ical calendar --- .gitignore | 5 ++--- bot.js | 43 ++++++++++++++++++++++++++++++----- package-lock.json | 57 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5fbc5e1..7447992 100644 --- a/.gitignore +++ b/.gitignore @@ -134,7 +134,6 @@ dist # End of https://www.toptal.com/developers/gitignore/api/node - config.json - -test \ No newline at end of file +test +public/ \ No newline at end of file diff --git a/bot.js b/bot.js index bbaeb33..e3a64e2 100644 --- a/bot.js +++ b/bot.js @@ -3,20 +3,28 @@ const axios = require("axios").default; const moment = require("moment"); +const ical = require("ical-generator").default; const config = require("./config.json"); -async function main() { - // let data = (await axios("https://vps.anotherfoxguy.com/dl/fur-events.json")).data; - let data = (await axios("https://api.fynn.ai/v1/events")).data; +//let events_data +async function main() { + //events_data = (await axios("https://vps.anotherfoxguy.com/dl/fur-events.json")).data; + events_data = (await axios("https://api.fynn.ai/v1/events")).data; + + //GenDiscord(); + GenIcal(); +} + +function GenDiscord() { let min = moment().add(1, "minutes"); // minutes let max = moment().add(61, "minutes"); // let max = moment().add(8, "hours"); //console.log(dat.data) - data = data.filter((event) => event.type != "Lobby"); + let data = events_data.filter((event) => event.type != "Lobby"); const events = data.filter((event) => moment.unix(event.start).isBetween(min, max) ); @@ -26,7 +34,7 @@ async function main() { events.forEach((event) => { console.log(event.name); - switch (event.type) { + switch (event.subType) { case "Meetup": colour = 1293056; break; @@ -88,4 +96,29 @@ async function main() { //let event = data[1]; } +function GenIcal() { + const calendar = ical({ + name: 'Furality Schedule', + description: 'Unofficial Furality Schedule created by AnotherFoxGuy', + source: 'https://furality.anotherfoxguy.com/calendar.ical', + ttl: 3600 + }); + + events_data.forEach((event) => { + calendar.createEvent({ + id: event.id, + start: moment.unix(event.start), + end: moment.unix(event.end), + summary: event.name, + description: event.description, + url: `https://furality.org/schedule#${event.id}`, + attachments: [ + event.imageUrl + ] + }); + }); + + calendar.save('./public/calendar.ical'); +} + main(); diff --git a/package-lock.json b/package-lock.json index 991c68f..a14598d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,6 +6,7 @@ "": { "dependencies": { "axios": "^1.4.0", + "ical-generator": "^4.1.0", "moment": "^2.29.4" } }, @@ -75,6 +76,57 @@ "node": ">= 6" } }, + "node_modules/ical-generator": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ical-generator/-/ical-generator-4.1.0.tgz", + "integrity": "sha512-5GrFDJ8SAOj8cB9P1uEZIfKrNxSZ1R2eOQfZePL+CtdWh4RwNXWe8b0goajz+Hu37vcipG3RVldoa2j57Y20IA==", + "dependencies": { + "uuid-random": "^1.3.2" + }, + "engines": { + "node": "^14.8.0 || >=16.0.0" + }, + "peerDependencies": { + "@touch4it/ical-timezones": ">=1.6.0", + "@types/luxon": ">= 1.26.0", + "@types/mocha": ">= 8.2.1", + "@types/node": ">= 15.0.0", + "dayjs": ">= 1.10.0", + "luxon": ">= 1.26.0", + "moment": ">= 2.29.0", + "moment-timezone": ">= 0.5.33", + "rrule": ">= 2.6.8" + }, + "peerDependenciesMeta": { + "@touch4it/ical-timezones": { + "optional": true + }, + "@types/luxon": { + "optional": true + }, + "@types/mocha": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "dayjs": { + "optional": true + }, + "luxon": { + "optional": true + }, + "moment": { + "optional": true + }, + "moment-timezone": { + "optional": true + }, + "rrule": { + "optional": true + } + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -106,6 +158,11 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/uuid-random": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/uuid-random/-/uuid-random-1.3.2.tgz", + "integrity": "sha512-UOzej0Le/UgkbWEO8flm+0y+G+ljUon1QWTEZOq1rnMAsxo2+SckbiZdKzAHHlVh6gJqI1TjC/xwgR50MuCrBQ==" } } } diff --git a/package.json b/package.json index 35e0c19..c3f6771 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "axios": "^1.4.0", + "ical-generator": "^4.1.0", "moment": "^2.29.4" } }