-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (28 loc) · 897 Bytes
/
index.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
const https = require('https');
const moment = require('moment');
const mail = require('./mail');
const toot = require('./toot');
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2));
moment.locale('de');
const today = moment().startOf('day');
https.get(process.env.EVENTS_URL, (res) => {
let body = '';
res.on('data', (chunk) => {body += chunk});
res.on('end', () => {
const data = JSON.parse(body);
data.forEach(event => {
if (event.start) {
const m = moment(event.start).startOf('day');
const diff = m.diff(today, 'days');
console.log('processing event id ' + event.uid + " / days: " + diff);
mail(event, diff);
toot(event, diff);
}
});
});
}).on('error', (e) => {
console.error("ERROR", e);
callback(e)
});
};