This repository was archived by the owner on Feb 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.js
47 lines (43 loc) · 1.56 KB
/
events.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
45
46
47
const express = require('express');
const cheerio = require('cheerio');
const { fetchData, handleError } = require('./utils');
const { LINKKI_EVENTS_URL, ALGO_EVENTS_URL } = require('./config');
const router = express.Router();
router.get('/linkki', async (req, res) => {
try {
const currentDate = new Date();
const twoMonthsFromNow = new Date();
twoMonthsFromNow.setMonth(twoMonthsFromNow.getMonth() + 2);
const baseUrl = `${LINKKI_EVENTS_URL}/[email protected]/events`;
const params = {
calendarId: '[email protected]',
singleEvents: 'true',
timeZone: 'Europe/Helsinki',
timeMin: currentDate.toISOString(),
timeMax: twoMonthsFromNow.toISOString(),
orderBy: 'startTime',
key: 'AIzaSyBNlYH01_9Hc5S1J9vuFmu2nUqBZJNAXxs'
};
const url = `${baseUrl}?${new URLSearchParams(params).toString()}`;
const data = await fetchData(url);
res.send(data);
} catch (err) {
handleError(err, res);
}
});
router.get('/algo', async (req, res) => {
try {
const html = await fetchData(ALGO_EVENTS_URL);
const $ = cheerio.load(html);
const events = [];
$('article.eventlist-event.eventlist-event--upcoming').each((i, el) => {
const summary = $(el).find('a.eventlist-title-link').text();
const date = $(el).find('time.event-date').attr('datetime');
events.push({ summary, start: { date: date } });
});
res.json({items: events});
} catch (err) {
handleError(err, res);
}
});
module.exports = router;