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.
Files changed (3) hide show
  1. package/README.md +7 -3
  2. package/bin/cli.js +114 -25
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # lscontests
2
2
 
3
+ ![GitHub Repo stars](https://img.shields.io/github/stars/StableAgOH/lscontests?style=social)
3
4
  ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/StableAgOH/lscontests)
4
5
  ![GitHub](https://img.shields.io/github/license/StableAgOH/lscontests)
5
6
  [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
7
+
6
8
  ![npm](https://img.shields.io/npm/v/lscontests)
9
+ ![npm](https://img.shields.io/npm/dw/lscontests)
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 output the version number
17
- -a, --all List all contests
18
- -d, --days Only list contests within a given number of days
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.1.0";
12
-
13
- async function get() {
14
- const result = (await axios__default["default"].get("https://codeforces.com/api/contest.list")).data.result;
15
- return result.map(contest => {
16
- return {
17
- oj: "Codeforces",
18
- name: contest.name,
19
- rule: contest.type,
20
- startTime: new Date(contest.startTimeSeconds * 1000),
21
- durationHours: contest.durationSeconds / 60 / 60,
22
- url: `https://codeforces.com/contests/${contest.id}`
23
- };
24
- }).filter(contest => contest.startTime >= new Date());
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 alloj = ["cf"];
28
- const getters = {
29
- "cf": get
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
- function getGetterList(ojs) {
32
- if (!ojs) ojs = alloj;
33
- return ojs.map(oj => getters[oj]);
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
- 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))));
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.1.0",
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": {