lscontests 1.1.0 → 1.2.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 (2) hide show
  1. package/bin/cli.js +48 -11
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -8,15 +8,19 @@ 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.1.0";
11
+ var version = "1.2.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
25
  durationHours: contest.durationSeconds / 60 / 60,
22
26
  url: `https://codeforces.com/contests/${contest.id}`
@@ -24,24 +28,57 @@ async function get() {
24
28
  }).filter(contest => contest.startTime >= new Date());
25
29
  }
26
30
 
27
- const alloj = ["cf"];
28
- const getters = {
29
- "cf": get
31
+ const ruleRecord = {
32
+ 1: "OI",
33
+ 2: "ICPC",
34
+ 3: "LeDuo",
35
+ 4: "IOI",
36
+ 5: "Codeforces"
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
+ durationHours: (contest.endTime - contest.startTime) / 60 / 60,
53
+ url: `https://www.luogu.com.cn/contest/${contest.id}`
54
+ };
55
+ }).filter(contest => contest.startTime >= new Date());
56
+ }
57
+
58
+ const alloj = {
59
+ "cf": {
60
+ name: "Codeforces",
61
+ getter: get$1
62
+ },
63
+ "lg": {
64
+ name: "Luogu",
65
+ getter: get
66
+ }
30
67
  };
31
68
  function getGetterList(ojs) {
32
- if (!ojs) ojs = alloj;
33
- return ojs.map(oj => getters[oj]);
69
+ if (!ojs) ojs = Object.keys(alloj);
70
+ return ojs.map(oj => alloj[oj].getter);
34
71
  }
35
72
 
36
73
  async function list(ojs, days) {
37
- return Promise.all(getGetterList(ojs).map(async get => (await get()).filter(ct => ct.startTime <= new Date(Date.now() + days * 86400000))));
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));
38
75
  }
39
76
 
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();
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();
41
78
  const opts = commander.program.opts();
42
79
 
43
80
  async function main() {
44
- if (opts.list) console.log(alloj);else console.log(await list(opts.oj, opts.days));
81
+ if (opts.list) console.log(Object.values(alloj).map(ojd => ojd.name));else console.log(await list(opts.oj, opts.days));
45
82
  }
46
83
 
47
84
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lscontests",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A CLI tool to get information about the contests on each OJ",
5
5
  "keywords": [
6
6
  "cli",