Skip to content

Commit de2020f

Browse files
committed
feat: add support for AtCoder
1 parent d00c300 commit de2020f

8 files changed

+278
-238
lines changed

.eslintrc.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"rules": {
1919
"indent": [
2020
"error",
21-
4
21+
4,
22+
{
23+
"SwitchCase": 1
24+
}
2225
],
2326
"linebreak-style": [
2427
"error",
@@ -28,13 +31,7 @@
2831
"error",
2932
"double"
3033
],
31-
"semi": [
32-
"error",
33-
"always"
34-
],
35-
"eol-last": [
36-
"error",
37-
"always"
38-
]
34+
"semi": "error",
35+
"eol-last": "error"
3936
}
4037
}

src/lib/contest.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export type rule = "OI" | "IOI" | "ICPC" | "LeDuo" | "Codeforces"
1+
export type rule = "OI" | "IOI" | "ICPC" | "LeDuo" | "Codeforces" | "AtCoder";
22
export type contest = {
33
ojName: string;
44
name: string;
55
rule: rule;
66
startTime: Date;
77
endTime: Date;
88
url: string;
9-
}
9+
};

src/lib/oj/atcoder.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import axios from "axios";
2+
import * as cheerio from "cheerio";
3+
import { contest } from "../contest";
4+
import { oj } from ".";
5+
6+
export const at: oj = {
7+
name: "AtCoder",
8+
get: async () => {
9+
const response = await axios.get("https://atcoder.jp/contests");
10+
const $ = cheerio.load(response.data);
11+
const contests: contest[] = [];
12+
$("#contest-table-upcoming table > tbody > tr").each(function () {
13+
const ct: contest = {
14+
ojName: at.name,
15+
name: "",
16+
rule: "AtCoder",
17+
startTime: new Date(0),
18+
endTime: new Date(0),
19+
url: ""
20+
};
21+
$("td", this).each(function (idx) {
22+
if (idx == 0) ct.startTime = new Date($(this).text());
23+
else if (idx == 1) {
24+
const ele = $("a", this);
25+
ct.name = `${$("span:first", this).text()} ${ele.text()}`;
26+
ct.url = `https://atcoder.jp${ele.attr().href}`;
27+
}
28+
else if (idx == 2) {
29+
const [h, s] = $(this).text().split(":");
30+
ct.endTime = new Date(ct.startTime.getTime() + (parseInt(h) * 60 + parseInt(s)) * 1000);
31+
}
32+
});
33+
contests.push(ct);
34+
});
35+
return contests;
36+
}
37+
};

src/lib/oj/codeforces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { contest, rule } from "../contest";
3-
import { oj } from "../oj";
3+
import { oj } from ".";
44

55
type result = {
66
id: string;

src/lib/oj.ts src/lib/oj/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { contest } from "./contest";
2-
import { cf } from "./oj/codeforces";
3-
import { lg } from "./oj/luogu";
4-
import { nc } from "./oj/nowcoder";
1+
import { contest } from "../contest";
2+
import { at } from "./atcoder";
3+
import { cf } from "./codeforces";
4+
import { lg } from "./luogu";
5+
import { nc } from "./nowcoder";
56

67
export type oj = {
78
name: string,
89
get: () => Promise<contest[]>
910
}
1011

1112
export const alloj: { [abbr: string]: oj } = {
13+
at,
1214
cf,
1315
lg,
14-
nc
16+
nc,
1517
};
1618

1719
export function addOJ(abbr: string, oj: oj) {

src/lib/oj/luogu.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios";
22
import { contest, rule } from "../contest";
3-
import { oj } from "../oj";
3+
import { oj } from ".";
44

55
type result = {
66
ruleType: number;

src/lib/oj/nowcoder.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from "axios";
22
import * as cheerio from "cheerio";
3+
import { oj } from ".";
34
import { contest, rule } from "../contest";
45

56
type result = {
@@ -69,10 +70,13 @@ const ruleRecord: Record<number, rule> = {
6970
2: "OI"
7071
};
7172

72-
export const nc = {
73+
export const nc: oj = {
7374
name: "NowCoder",
7475
get: async () => {
75-
const res: result[] = [...await getResultList(topCategoryFilter.NOWCODERSERIES), ...await getResultList(topCategoryFilter.SCHOOLCONTEST)];
76+
const res: result[] = [
77+
...await getResultList(topCategoryFilter.NOWCODERSERIES),
78+
...await getResultList(topCategoryFilter.SCHOOLCONTEST)
79+
];
7680
return res.filter((res) => res.signUpEndCountDownTime > 0).map((res): contest => {
7781
return {
7882
ojName: nc.name,

0 commit comments

Comments
 (0)