mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-01 17:48:15 +08:00
Add(route): add Codeforces contests (#8815)
Co-authored-by: HuangWei <huangwei.a180285@gmail.com> Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
37
lib/v2/codeforces/contests.js
Normal file
37
lib/v2/codeforces/contests.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const got = require('@/utils/got');
|
||||
const path = require('path');
|
||||
const { art } = require('@/utils/render');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const contestAPI = 'https://codeforces.com/api/contest.list';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const contestsData = await got.get(contestAPI).json();
|
||||
const contests = contestsData.result;
|
||||
|
||||
const items = contests
|
||||
.filter((contests) => contests.phase === 'BEFORE')
|
||||
.map((contest) => {
|
||||
const title = String(contest.name);
|
||||
const description = art(path.join(__dirname, 'templates/contest.art'), {
|
||||
title,
|
||||
startTime: timezone(parseDate(contest.startTimeSeconds * 1000), +0),
|
||||
durationTime: contest.durationSeconds / 60,
|
||||
relativeTime: Math.floor(contest.relativeTimeSeconds / 60),
|
||||
type: contest.type,
|
||||
});
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
link: 'https://codeforces.com/contests/' + contest.id,
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Codeforces - Contests',
|
||||
link: 'https://codeforces.com/contests',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user