-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
244f8ca
commit 9b9ce25
Showing
9 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,4 @@ dist | |
.tern-port | ||
|
||
bin | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "pwa-node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}\\cli.ts", | ||
"preLaunchTask": "tsc: 构建 - tsconfig.json", | ||
"outFiles": [ | ||
"${workspaceFolder}/output/**/*.js" | ||
], | ||
"args": ["-d 7"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "typescript", | ||
"tsconfig": "tsconfig.json", | ||
"problemMatcher": [ | ||
"$tsc" | ||
], | ||
"group": "build", | ||
"label": "tsc: 构建 - tsconfig.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import codeforces from "./codeforces"; | ||
import luogu from "./luogu"; | ||
|
||
export interface Contest { | ||
oj: string; | ||
export type oj = "cf" | "lg"; | ||
type ojName = "Codeforces" | "Luogu"; | ||
type ojDetail = { | ||
name: ojName, | ||
getter: () => Promise<Contest[]> | ||
} | ||
type ojRecord = Record<oj, ojDetail> | ||
export type contestRule = "OI" | "IOI" | "ICPC" | "LeDuo" | "Codeforces" | ||
|
||
export type Contest = { | ||
oj: ojName; | ||
name: string; | ||
rule: string; | ||
rule: contestRule; | ||
startTime: Date; | ||
durationHours: number; | ||
url: string; | ||
} | ||
|
||
export type oj = "cf"; | ||
|
||
export const alloj: oj[] = ["cf"]; | ||
|
||
export const getters: Record<oj, () => Promise<Contest[]>> = { | ||
"cf": codeforces, | ||
export const alloj: ojRecord = { | ||
"cf": { name: "Codeforces", getter: codeforces }, | ||
"lg": { name: "Luogu", getter: luogu } | ||
}; | ||
|
||
export function getGetterList(ojs: oj[]) { | ||
if (!ojs) ojs = alloj; | ||
return ojs.map((oj) => getters[oj]); | ||
if (!ojs) ojs = Object.keys(alloj) as oj[]; | ||
return ojs.map((oj) => alloj[oj].getter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import { Contest, contestRule } from "./contest"; | ||
|
||
type LuoguResult = { | ||
ruleType: number; | ||
visibilityType: number; | ||
invitationCodeType: number; | ||
rated: boolean; | ||
host: { id: number, name: string, isPremium: boolean }; | ||
problemCount: number; | ||
id: number; | ||
name: string; | ||
startTime: number; | ||
endTime: number; | ||
} | ||
|
||
const ruleRecord: Record<number, contestRule> = { | ||
1: "OI", | ||
2: "ICPC", | ||
3: "LeDuo", | ||
4: "IOI", | ||
5: "Codeforces" | ||
}; | ||
|
||
const headers = { | ||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36", | ||
"x-luogu-type": "content-only" | ||
}; | ||
|
||
export default async function get() { | ||
const result: LuoguResult[] = (await axios.get("https://www.luogu.com.cn/contest/list", { headers })).data.currentData.contests.result; | ||
return result.map((contest): Contest => { | ||
return { | ||
oj: "Luogu", | ||
name: contest.name, | ||
rule: ruleRecord[contest.ruleType], | ||
startTime: new Date(contest.startTime * 1000), | ||
durationHours: (contest.endTime - contest.startTime) / 60 / 60, | ||
url: `https://www.luogu.com.cn/contest/${contest.id}` | ||
}; | ||
}).filter((contest) => contest.startTime >= new Date()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { getGetterList, oj } from "./contest/contest"; | ||
|
||
export default async function list(ojs: oj[], days: number) { | ||
return Promise.all( | ||
return (await Promise.all( | ||
getGetterList(ojs).map( | ||
async (get) => (await get()).filter( | ||
(ct) => ct.startTime <= new Date(Date.now() + (days as number) * 86400000) | ||
) | ||
) | ||
); | ||
)).reduce((ls1, ls2) => ls1.concat(ls2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters