🎉 Generate ical calendar

This commit is contained in:
Edgar 2023-05-27 17:07:52 +02:00
parent 2e335b5382
commit fae86d6f9f
No known key found for this signature in database
GPG Key ID: 9AA5DDFFCBDCE46A
4 changed files with 98 additions and 8 deletions

5
.gitignore vendored
View File

@ -134,7 +134,6 @@ dist
# End of https://www.toptal.com/developers/gitignore/api/node
config.json
test
test
public/

43
bot.js
View File

@ -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();

57
package-lock.json generated
View File

@ -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=="
}
}
}

View File

@ -1,6 +1,7 @@
{
"dependencies": {
"axios": "^1.4.0",
"ical-generator": "^4.1.0",
"moment": "^2.29.4"
}
}