-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcodechef.js
36 lines (29 loc) · 1.07 KB
/
codechef.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
const fetch = require('node-fetch');
const moment = require('moment');
const cheerio = require('cheerio');
module.exports.name = 'CodeChef';
module.exports.icon = {
url: 'https://www.codechef.com/misc/favicon.ico',
variety: 'circular'
};
module.exports.contests = fetch('https://www.codechef.com/contests/').then(res => res.text()).then(body => {
let contests = [];
const $ = cheerio.load(body);
$('#future-contests+div>table>tbody>tr').each((index, tr) => {
let meta = {};
$(tr).find('td').each((index, td) => {
const $td = $(td);
switch (index) {
case 0:
meta.id = $td.text();
meta.url = `https://www.codechef.com/${meta.id}`;
break;
case 1: meta.name = $td.find('a').text(); break;
case 2: meta.startTime = moment($td.attr('data-starttime')); break;
case 3: meta.endTime = moment($td.attr('data-endtime')); break;
}
});
contests.push(meta);
});
return contests;
});