mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 15:05:38 -04:00
[pl][calendar] generate ics for miastamaszerujace.pl
This commit is contained in:
parent
250e9be1aa
commit
2d6bf09cb0
@ -5,6 +5,7 @@ const { JSDOM } = require("jsdom");
|
|||||||
const { Day } = require('../src/calendar/helpers');
|
const { Day } = require('../src/calendar/helpers');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const mailer = require('../src/mailer');
|
const mailer = require('../src/mailer');
|
||||||
|
const { createEvents } = require('ics');
|
||||||
|
|
||||||
const year = Day.today().year;
|
const year = Day.today().year;
|
||||||
|
|
||||||
@ -36,7 +37,9 @@ const fetchEvents = async () => {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const events = await fetchEvents();
|
const events = await fetchEvents();
|
||||||
console.log(events);
|
console.log(events);
|
||||||
const path = `${__dirname}/../static/calendar/miastamaszerujace-${year}.json`;
|
|
||||||
|
const dir = `${__dirname}/../static/calendar`;
|
||||||
|
const path = `${dir}/miastamaszerujace-${year}.json`;
|
||||||
const previous = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path).toString('UTF-8')) : null;
|
const previous = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path).toString('UTF-8')) : null;
|
||||||
if (JSON.stringify(events) !== JSON.stringify(previous)) {
|
if (JSON.stringify(events) !== JSON.stringify(previous)) {
|
||||||
console.log('wykryto zmiany, wysyłam maila');
|
console.log('wykryto zmiany, wysyłam maila');
|
||||||
@ -47,4 +50,24 @@ const fetchEvents = async () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
fs.writeFileSync(path, JSON.stringify(events, null, 4));
|
fs.writeFileSync(path, JSON.stringify(events, null, 4));
|
||||||
|
|
||||||
|
createEvents(
|
||||||
|
events.map((e, i) => {
|
||||||
|
return {
|
||||||
|
title: e.name,
|
||||||
|
start: [e.date.year, e.date.month, e.date.day],
|
||||||
|
end: [e.date.year, e.date.month, e.date.day],
|
||||||
|
calName: `Marsze Równości ${year}`,
|
||||||
|
sequence: i,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
(error, value) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(`${dir}/miastamaszerujace.ics`, value);
|
||||||
|
}
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user