rsshub
Version:
Make RSS Great Again!
97 lines (90 loc) • 3.48 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { load } from "cheerio";
//#region lib/routes/atcoder/contest.ts
const route = {
path: "/contest/:language?/:rated?/:category?/:keyword?",
categories: ["programming"],
example: "/atcoder/contest",
parameters: {
language: "Language, `jp` as Japanese or `en` as English, English by default",
rated: "Rated Range, see below, all by default",
category: "Category, see below, all by default",
keyword: "Keyword"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "Contests Archive",
maintainers: ["nczitzk"],
handler,
description: `Rated Range
| ABC Class (Rated for \~1999) | ARC Class (Rated for \~2799) | AGC Class (Rated for \~9999) |
| ---------------------------- | ---------------------------- | ---------------------------- |
| 1 | 2 | 3 |
Category
| All | AtCoder Typical Contest | PAST Archive | Unofficial(unrated) |
| --- | ----------------------- | ------------ | ------------------- |
| 0 | 6 | 50 | 101 |
| JOI Archive | Sponsored Tournament | Sponsored Parallel(rated) |
| ----------- | -------------------- | ------------------------- |
| 200 | 1000 | 1001 |
| Sponsored Parallel(unrated) | Optimization Contest |
| --------------------------- | -------------------- |
| 1002 | 1200 |`
};
async function handler(ctx) {
const status = [
"action",
"upcoming",
"recent"
];
const language = ctx.req.param("language") ?? "en";
let rated = ctx.req.param("rated") ?? "0";
const category = ctx.req.param("category") ?? "0";
const keyword = ctx.req.param("keyword") ?? "";
rated = rated === "active" ? "action" : rated;
const isStatus = status.includes(rated);
const rootUrl = "https://atcoder.jp";
const currentUrl = `${rootUrl}/contests${isStatus ? `?lang=${language}` : `/archive?lang=${language}&ratedType=${rated}&category=${category}${keyword ? `&keyword=${keyword}` : ""}`}`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
let items = $(isStatus ? `#contest-table-${rated}` : ".row").find("tr").slice(1, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20).toArray().map((item) => {
item = $(item).find("td a").eq(1);
return {
title: item.text(),
link: `${rootUrl}${item.attr("href")}?lang=${language}`
};
});
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
item.description = content(`.lang-${language}`).html();
item.pubDate = parseDate(content(".fixtime-full").first().text());
return item;
})));
return {
title: String(isStatus ? `${$(`#contest-table-${rated} h3`).text()} - AtCoder` : $("title").text()),
link: currentUrl,
item: items,
allowEmpty: true
};
}
//#endregion
export { route };