From bc35a1e937f9a7dd0c34dc8b8980ceef2e8dff36 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sun, 23 Jan 2022 04:10:59 +0800 Subject: [PATCH] Add(route): add Codeforces contests (#8815) Co-authored-by: HuangWei Co-authored-by: DIYgod --- docs/en/programming.md | 6 ++++ docs/programming.md | 6 ++++ lib/v2/codeforces/contests.js | 37 +++++++++++++++++++++++++ lib/v2/codeforces/maintainer.js | 3 ++ lib/v2/codeforces/radar.js | 13 +++++++++ lib/v2/codeforces/router.js | 3 ++ lib/v2/codeforces/templates/contest.art | 11 ++++++++ 7 files changed, 79 insertions(+) create mode 100644 lib/v2/codeforces/contests.js create mode 100644 lib/v2/codeforces/maintainer.js create mode 100644 lib/v2/codeforces/radar.js create mode 100644 lib/v2/codeforces/router.js create mode 100644 lib/v2/codeforces/templates/contest.art diff --git a/docs/en/programming.md b/docs/en/programming.md index f3c78fdf90..8764e824a9 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -10,6 +10,12 @@ pageClass: routes +## Codeforces + +### Latest contests + + + ## AtCoder ### Present Contests diff --git a/docs/programming.md b/docs/programming.md index 736c52add9..0a1a6fd085 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -24,6 +24,12 @@ pageClass: routes > AlgoCasts 需要付费订阅,RSS 仅做更新提醒,不含付费内容. +## Codeforces + +#### 最新比赛 + + + ## AtCoder ### Present Contests diff --git a/lib/v2/codeforces/contests.js b/lib/v2/codeforces/contests.js new file mode 100644 index 0000000000..82a6de86d0 --- /dev/null +++ b/lib/v2/codeforces/contests.js @@ -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, + }; +}; diff --git a/lib/v2/codeforces/maintainer.js b/lib/v2/codeforces/maintainer.js new file mode 100644 index 0000000000..1d57fdfe35 --- /dev/null +++ b/lib/v2/codeforces/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/contests': ['Fatpandac'], +}; diff --git a/lib/v2/codeforces/radar.js b/lib/v2/codeforces/radar.js new file mode 100644 index 0000000000..366f1178dd --- /dev/null +++ b/lib/v2/codeforces/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'codeforces.com': { + _name: 'Codeforces', + www: [ + { + title: '最新比赛', + docs: 'https://docs.rsshub.app/programming.html#codeforces-zui-xin-bi-sai', + source: ['/contests'], + target: '/codeforces/contests', + }, + ], + }, +}; diff --git a/lib/v2/codeforces/router.js b/lib/v2/codeforces/router.js new file mode 100644 index 0000000000..2c28d05ceb --- /dev/null +++ b/lib/v2/codeforces/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/contests', require('./contests')); +}; diff --git a/lib/v2/codeforces/templates/contest.art b/lib/v2/codeforces/templates/contest.art new file mode 100644 index 0000000000..f590caa7fd --- /dev/null +++ b/lib/v2/codeforces/templates/contest.art @@ -0,0 +1,11 @@ +比赛:{{ title }} +
+开始时间:{{ startTime }} +
+持续时间:{{ durationTime }} 分钟 +
+相对时间:{{ relativeTime }} 分钟 +
+比赛类型:{{ type }} +
+