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.
Files changed (3) hide show
  1. package/README.md +4 -3
  2. package/bin/cli.js +50 -17
  3. 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 output the version number
17
- -a, --all List all contests
18
- -d, --days Only list contests within a given number of days
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.1";
11
+ var version = "1.3.0";
12
12
 
13
- async function get() {
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
- durationHours: contest.durationSeconds / 60 / 60,
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 getters = {
28
- "codeforces": get
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
- async function list(getters, days) {
32
- const cts = [];
33
-
34
- for (const get of getters) {
35
- const res = await get();
36
- cts.push(...res.filter(ct => ct.startTime <= new Date(Date.now() + days * 86400000)));
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
- return cts;
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("-a, --all", "List all contests").option("-d, --days", "Only list contests within a given number of days", "3").parse();
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
- const cts = [];
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lscontests",
3
- "version": "1.0.1",
3
+ "version": "1.3.0",
4
4
  "description": "A CLI tool to get information about the contests on each OJ",
5
5
  "keywords": [
6
6
  "cli",