lscontests 1.3.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 +3 -0
  2. package/bin/cli.js +99 -47
  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
 
package/bin/cli.js CHANGED
@@ -3,32 +3,55 @@
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.3.0";
31
+ var version = "1.4.0";
12
32
 
13
- const ruleRecord$1 = {
14
- "CF": "Codeforces",
15
- "ICPC": "ICPC"
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
+ }
16
52
  };
17
- async function get$1() {
18
- const result = (await axios__default["default"].get("https://codeforces.com/api/contest.list")).data.result;
19
- return result.map(contest => {
20
- return {
21
- oj: "Codeforces",
22
- name: contest.name,
23
- rule: ruleRecord$1[contest.type],
24
- startTime: new Date(contest.startTimeSeconds * 1000),
25
- endTime: new Date((contest.startTimeSeconds + contest.durationSeconds) * 1000),
26
- url: `https://codeforces.com/contests/${contest.id}`
27
- };
28
- }).filter(contest => contest.startTime >= new Date());
29
- }
30
53
 
31
- const ruleRecord = {
54
+ const ruleRecord$1 = {
32
55
  1: "OI",
33
56
  2: "ICPC",
34
57
  3: "LeDuo",
@@ -39,46 +62,75 @@ const headers = {
39
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",
40
63
  "x-luogu-type": "content-only"
41
64
  };
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());
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
+ }
82
+ };
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;
56
94
  }
57
95
 
58
- const alloj = {
59
- "cf": {
60
- name: "Codeforces",
61
- getter: get$1
62
- },
63
- "lg": {
64
- name: "Luogu",
65
- getter: get
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
+ });
66
115
  }
67
116
  };
68
- function getGetterList(ojs) {
69
- if (!ojs) ojs = Object.keys(alloj);
70
- return ojs.map(oj => alloj[oj].getter);
71
- }
72
117
 
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));
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));
75
127
  }
76
128
 
77
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();
78
130
  const opts = commander.program.opts();
79
131
 
80
132
  async function main() {
81
- if (opts.list) console.log(Object.values(alloj).map(ojd => ojd.name));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));
82
134
  }
83
135
 
84
136
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lscontests",
3
- "version": "1.3.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": {