lscontests 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/bin/cli.js +50 -17
- package/package.json +1 -1
package/README.md
CHANGED
@@ -13,9 +13,10 @@ A CLI tool to get information about the contests on each OJ
|
|
13
13
|
lsct [options]
|
14
14
|
|
15
15
|
Options:
|
16
|
-
-V, --version
|
17
|
-
-
|
18
|
-
-
|
16
|
+
-V, --version output the version number
|
17
|
+
-d, --days, <day> Number of days to get contests information (default: "3")
|
18
|
+
-l, --list List all supported OJ
|
19
|
+
-o, --oj <ojs...> OJs to get contests information (choices: "cf", "lg")
|
19
20
|
```
|
20
21
|
|
21
22
|
## License
|
package/bin/cli.js
CHANGED
@@ -8,44 +8,77 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
8
8
|
|
9
9
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
10
10
|
|
11
|
-
var version = "1.0
|
11
|
+
var version = "1.3.0";
|
12
12
|
|
13
|
-
|
13
|
+
const ruleRecord$1 = {
|
14
|
+
"CF": "Codeforces",
|
15
|
+
"ICPC": "ICPC"
|
16
|
+
};
|
17
|
+
async function get$1() {
|
14
18
|
const result = (await axios__default["default"].get("https://codeforces.com/api/contest.list")).data.result;
|
15
19
|
return result.map(contest => {
|
16
20
|
return {
|
17
21
|
oj: "Codeforces",
|
18
22
|
name: contest.name,
|
19
|
-
rule: contest.type,
|
23
|
+
rule: ruleRecord$1[contest.type],
|
20
24
|
startTime: new Date(contest.startTimeSeconds * 1000),
|
21
|
-
|
25
|
+
endTime: new Date((contest.startTimeSeconds + contest.durationSeconds) * 1000),
|
22
26
|
url: `https://codeforces.com/contests/${contest.id}`
|
23
27
|
};
|
24
28
|
}).filter(contest => contest.startTime >= new Date());
|
25
29
|
}
|
26
30
|
|
27
|
-
const
|
28
|
-
"
|
31
|
+
const ruleRecord = {
|
32
|
+
1: "OI",
|
33
|
+
2: "ICPC",
|
34
|
+
3: "LeDuo",
|
35
|
+
4: "IOI",
|
36
|
+
5: "Codeforces"
|
29
37
|
};
|
38
|
+
const headers = {
|
39
|
+
"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",
|
40
|
+
"x-luogu-type": "content-only"
|
41
|
+
};
|
42
|
+
async function get() {
|
43
|
+
const result = (await axios__default["default"].get("https://www.luogu.com.cn/contest/list", {
|
44
|
+
headers
|
45
|
+
})).data.currentData.contests.result;
|
46
|
+
return result.map(contest => {
|
47
|
+
return {
|
48
|
+
oj: "Luogu",
|
49
|
+
name: contest.name,
|
50
|
+
rule: ruleRecord[contest.ruleType],
|
51
|
+
startTime: new Date(contest.startTime * 1000),
|
52
|
+
endTime: new Date(contest.endTime * 1000),
|
53
|
+
url: `https://www.luogu.com.cn/contest/${contest.id}`
|
54
|
+
};
|
55
|
+
}).filter(contest => contest.startTime >= new Date());
|
56
|
+
}
|
30
57
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
58
|
+
const alloj = {
|
59
|
+
"cf": {
|
60
|
+
name: "Codeforces",
|
61
|
+
getter: get$1
|
62
|
+
},
|
63
|
+
"lg": {
|
64
|
+
name: "Luogu",
|
65
|
+
getter: get
|
37
66
|
}
|
67
|
+
};
|
68
|
+
function getGetterList(ojs) {
|
69
|
+
if (!ojs) ojs = Object.keys(alloj);
|
70
|
+
return ojs.map(oj => alloj[oj].getter);
|
71
|
+
}
|
38
72
|
|
39
|
-
|
73
|
+
async function list(ojs, days) {
|
74
|
+
return (await Promise.all(getGetterList(ojs).map(async get => (await get()).filter(ct => ct.startTime <= new Date(Date.now() + days * 86400000))))).reduce((ls1, ls2) => ls1.concat(ls2));
|
40
75
|
}
|
41
76
|
|
42
|
-
commander.program.name("lsct").version(version).option("-
|
77
|
+
commander.program.name("lsct").version(version).option("-d, --days, <day>", "Number of days to get contests information", "3").option("-l, --list", "List all supported OJ").addOption(new commander.Option("-o, --oj <ojs...>", "OJs to get contests information").choices(Object.keys(alloj))).parse();
|
43
78
|
const opts = commander.program.opts();
|
44
79
|
|
45
80
|
async function main() {
|
46
|
-
|
47
|
-
if (commander.program.args.length === 0 || opts.all) cts.push(...(await list(Object.values(getters), opts.days)));
|
48
|
-
console.log(cts);
|
81
|
+
if (opts.list) console.log(Object.values(alloj).map(ojd => ojd.name));else console.log(await list(opts.oj, opts.days));
|
49
82
|
}
|
50
83
|
|
51
84
|
main();
|