-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuoj.js
46 lines (37 loc) · 1.35 KB
/
uoj.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
const fetch = require('node-fetch');
const moment = require('moment');
const cheerio = require('cheerio');
module.exports.name = 'UOJ';
module.exports.icon = {
url: 'http://uoj.ac/pictures/UOJ_small.png',
variety: 'circular'
};
module.exports.contests = fetch('https://uoj.ac/contests').then(res => res.text()).then(body => {
let contests = [];
const $ = cheerio.load(body);
$('.uoj-content>.table-responsive:first-of-type>table>tbody>tr').each((index, tr) => {
const $tr = $(tr);
if ($tr.children('td').length !== 5) return;
let meta = {};
$tr.find('td').each((index, td) => {
const $td = $(td);
switch (index) {
case 0: {
let $a = $td.children('a');
meta.id = parseInt($a.attr('href').split('/').pop());
meta.name = $a.text();
meta.url = `https://uoj.ac/contest/${meta.id}`;
break;
}
case 1: meta.startTime = moment($td.find('a').text()); break;
case 2: {
let hours = $td.text().match(/^([\d.]+) .+$/)[1];
meta.endTime = moment(meta.startTime).add(hours, 'h');
break;
}
}
});
contests.push(meta);
});
return contests;
});