generated from petrkucerak/under-construction
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathical-generator.js
44 lines (42 loc) · 1.29 KB
/
ical-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require("fs");
const ics = require("ics");
const program = require("./components/switcher/program.json");
program.map((event) => {
const time = event.time.split(":");
ics.createEvent(
{
title: event.name,
url: "https://diecezko.cz/",
description: event.description.replaceAll(" ", " "),
// busyStatus: "FREE",
organizer: {
name: "Pan Holub",
email: "[email protected]",
dir: "https://diecezko.cz/evzenova-cesta",
sentBy: "[email protected]",
},
location: event.place !== undefined ? event.place.name : undefined,
geo:
event.place !== undefined && event.place.coords !== undefined
? {
lat: parseFloat(event.place.coords.x),
lon: parseFloat(event.place.coords.y),
}
: undefined,
start: [2024, 3, 23, parseInt(time[0]), parseInt(time[1])],
duration: { minutes: event.duration },
},
(error, value) => {
if (error) {
console.log(error);
}
const path = `./public/assets/events/${event.time.replace(":", "")}${
event.id
}`;
if (!fs.existsSync(path)) fs.mkdirSync(path);
const file = fs.createWriteStream(`${path}/event.ics`);
file.write(value);
file.close();
}
);
});