import './setup.ts';
import fetch from 'node-fetch';
import { JSDOM } from 'jsdom';
import * as Sentry from '@sentry/node';
import { Day } from '../src/calendar/helpers.ts';
import fs from 'fs';
import mailer from '../src/mailer.ts';
import type { MiastamaszerujaceEvent } from '../src/calendar/helpers.ts';
import { createEvents } from 'ics';
const __dirname = new URL('.', import.meta.url).pathname;
const year = Day.today().year;
const fetchEvents = async (): Promise
', 'g'), '
')
.replace(new RegExp('(.*?)', 'g'), '$1'));
const eventsImgs = dom.window.document.querySelectorAll('img[src="https://miastamaszerujace.pl/wp-content/uploads/2021/11/Zasob-6@4x.png"]');
for (const eventImg of eventsImgs) {
const p = eventImg.closest('p')!;
if (p.textContent!.includes('Daty kolejnych') || p.textContent!.includes('Marsz organizowany przez grupę współpracującą')) {
continue;
}
const [day, month] = p.querySelector('b,strong')!.textContent!.trim().split('/');
const date = new Day(year, parseInt(month), parseInt(day));
const name = [...p.childNodes]
.filter((c) => c.nodeType === 3 /* text node */ || c.nodeName === 'A')
.map((c) => c.textContent!.trim())
.filter((t) => !!t)
.join(' ');
let link = null;
try {
link = new URL(p.querySelector('a')!.getAttribute('href')!);
link.hash = '';
link.search = '';
} catch (e) {}
events.push({
name,
date,
link: link ? link.toString() : null,
});
}
return events;
};
(async (): Promise