lscontests 1.1.0 → 1.4.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 +7 -3
- package/bin/cli.js +114 -25
- package/package.json +2 -1
package/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# lscontests
|
2
2
|
|
3
|
+

|
3
4
|

|
4
5
|

|
5
6
|
[](https://github.com/semantic-release/semantic-release)
|
7
|
+
|
6
8
|

|
9
|
+

|
7
10
|
|
8
11
|
A CLI tool to get information about the contests on each OJ
|
9
12
|
|
@@ -13,9 +16,10 @@ A CLI tool to get information about the contests on each OJ
|
|
13
16
|
lsct [options]
|
14
17
|
|
15
18
|
Options:
|
16
|
-
-V, --version
|
17
|
-
-
|
18
|
-
-
|
19
|
+
-V, --version output the version number
|
20
|
+
-d, --days, <day> Number of days to get contests information (default: "3")
|
21
|
+
-l, --list List all supported OJ
|
22
|
+
-o, --oj <ojs...> OJs to get contests information (choices: "cf", "lg")
|
19
23
|
```
|
20
24
|
|
21
25
|
## License
|
package/bin/cli.js
CHANGED
@@ -3,45 +3,134 @@
|
|
3
3
|
|
4
4
|
var commander = require('commander');
|
5
5
|
var axios = require('axios');
|
6
|
+
var cheerio = require('cheerio');
|
6
7
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
8
9
|
|
10
|
+
function _interopNamespace(e) {
|
11
|
+
if (e && e.__esModule) return e;
|
12
|
+
var n = Object.create(null);
|
13
|
+
if (e) {
|
14
|
+
Object.keys(e).forEach(function (k) {
|
15
|
+
if (k !== 'default') {
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
18
|
+
enumerable: true,
|
19
|
+
get: function () { return e[k]; }
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
n["default"] = e;
|
25
|
+
return Object.freeze(n);
|
26
|
+
}
|
27
|
+
|
9
28
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
29
|
+
var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
|
10
30
|
|
11
|
-
var version = "1.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
var version = "1.4.0";
|
32
|
+
|
33
|
+
const ruleRecord$2 = {
|
34
|
+
CF: "Codeforces",
|
35
|
+
ICPC: "ICPC"
|
36
|
+
};
|
37
|
+
const cf = {
|
38
|
+
name: "Codeforces",
|
39
|
+
get: async () => {
|
40
|
+
const resList = (await axios__default["default"].get("https://codeforces.com/api/contest.list")).data.result;
|
41
|
+
return resList.map(res => {
|
42
|
+
return {
|
43
|
+
ojName: cf.name,
|
44
|
+
name: res.name,
|
45
|
+
rule: ruleRecord$2[res.type],
|
46
|
+
startTime: new Date(res.startTimeSeconds * 1000),
|
47
|
+
endTime: new Date((res.startTimeSeconds + res.durationSeconds) * 1000),
|
48
|
+
url: `https://codeforces.com/contests/${res.id}`
|
49
|
+
};
|
50
|
+
}).filter(contest => contest.startTime >= new Date());
|
51
|
+
}
|
52
|
+
};
|
26
53
|
|
27
|
-
const
|
28
|
-
|
29
|
-
"
|
54
|
+
const ruleRecord$1 = {
|
55
|
+
1: "OI",
|
56
|
+
2: "ICPC",
|
57
|
+
3: "LeDuo",
|
58
|
+
4: "IOI",
|
59
|
+
5: "Codeforces"
|
60
|
+
};
|
61
|
+
const headers = {
|
62
|
+
"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",
|
63
|
+
"x-luogu-type": "content-only"
|
64
|
+
};
|
65
|
+
const lg = {
|
66
|
+
name: "Luogu",
|
67
|
+
get: async () => {
|
68
|
+
const resList = (await axios__default["default"].get("https://www.luogu.com.cn/contest/list", {
|
69
|
+
headers
|
70
|
+
})).data.currentData.contests.result;
|
71
|
+
return resList.map(res => {
|
72
|
+
return {
|
73
|
+
ojName: lg.name,
|
74
|
+
name: res.name,
|
75
|
+
rule: ruleRecord$1[res.ruleType],
|
76
|
+
startTime: new Date(res.startTime * 1000),
|
77
|
+
endTime: new Date(res.endTime * 1000),
|
78
|
+
url: `https://www.luogu.com.cn/contest/${res.id}`
|
79
|
+
};
|
80
|
+
}).filter(contest => contest.startTime >= new Date());
|
81
|
+
}
|
30
82
|
};
|
31
|
-
|
32
|
-
|
33
|
-
|
83
|
+
|
84
|
+
const url = "https://ac.nowcoder.com/acm/contest/vip-index";
|
85
|
+
|
86
|
+
async function getResultList(topCategoryFilter) {
|
87
|
+
const html = (await axios__default["default"].get(`${url}?topCategoryFilter=${topCategoryFilter}`)).data;
|
88
|
+
const $ = cheerio__namespace.load(html);
|
89
|
+
const ls = [];
|
90
|
+
$("div[class='platform-item js-item ']").each(function () {
|
91
|
+
ls.push(JSON.parse(cheerio__namespace.load(this.attribs["data-json"]).text()));
|
92
|
+
});
|
93
|
+
return ls;
|
34
94
|
}
|
35
95
|
|
36
|
-
|
37
|
-
|
96
|
+
const ruleRecord = {
|
97
|
+
0: "ICPC",
|
98
|
+
1: "IOI",
|
99
|
+
2: "OI"
|
100
|
+
};
|
101
|
+
const nc = {
|
102
|
+
name: "NowCoder",
|
103
|
+
get: async () => {
|
104
|
+
const res = [...(await getResultList(13)), ...(await getResultList(14))];
|
105
|
+
return res.filter(res => res.signUpEndCountDownTime > 0).map(res => {
|
106
|
+
return {
|
107
|
+
ojName: nc.name,
|
108
|
+
name: res.contestName,
|
109
|
+
rule: ruleRecord[res.type],
|
110
|
+
startTime: new Date(res.contestStartTime),
|
111
|
+
endTime: new Date(res.contestEndTime),
|
112
|
+
url: `https://ac.nowcoder.com/acm/contest/${res.contestId}`
|
113
|
+
};
|
114
|
+
});
|
115
|
+
}
|
116
|
+
};
|
117
|
+
|
118
|
+
const alloj = {
|
119
|
+
cf,
|
120
|
+
lg,
|
121
|
+
nc
|
122
|
+
};
|
123
|
+
|
124
|
+
async function list(abbrList, days) {
|
125
|
+
if (!abbrList) abbrList = Object.keys(alloj);
|
126
|
+
return (await Promise.all(abbrList.map(async abbr => (await alloj[abbr].get()).filter(ct => ct.startTime <= new Date(Date.now() + days * 86400000))))).reduce((ls1, ls2) => ls1.concat(ls2));
|
38
127
|
}
|
39
128
|
|
40
|
-
commander.program.name("lsct").version(version).option("-d, --days", "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(alloj)).parse();
|
129
|
+
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();
|
41
130
|
const opts = commander.program.opts();
|
42
131
|
|
43
132
|
async function main() {
|
44
|
-
if (opts.list) console.log(alloj);else console.log(await list(opts.oj, opts.days));
|
133
|
+
if (opts.list) console.log(Object.values(alloj).map(oj => oj.name));else console.log(await list(opts.oj, opts.days));
|
45
134
|
}
|
46
135
|
|
47
136
|
main();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "lscontests",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.0",
|
4
4
|
"description": "A CLI tool to get information about the contests on each OJ",
|
5
5
|
"keywords": [
|
6
6
|
"cli",
|
@@ -24,6 +24,7 @@
|
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
26
|
"axios": "^0.27.2",
|
27
|
+
"cheerio": "^1.0.0-rc.10",
|
27
28
|
"commander": "^9.2.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|