lscontests 1.0.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 (3) hide show
  1. package/README.md +22 -0
  2. package/bin/cli.js +84 -0
  3. package/package.json +13 -2
package/README.md CHANGED
@@ -1 +1,23 @@
1
1
  # lscontests
2
+
3
+ ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/StableAgOH/lscontests)
4
+ ![GitHub](https://img.shields.io/github/license/StableAgOH/lscontests)
5
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
6
+ ![npm](https://img.shields.io/npm/v/lscontests)
7
+
8
+ A CLI tool to get information about the contests on each OJ
9
+
10
+ ## Usage
11
+
12
+ ```bash
13
+ lsct [options]
14
+
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
19
+ ```
20
+
21
+ ## License
22
+
23
+ [GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.html)
package/bin/cli.js ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var commander = require('commander');
5
+ var axios = require('axios');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
+
11
+ var version = "1.2.0";
12
+
13
+ const ruleRecord$1 = {
14
+ "CF": "Codeforces",
15
+ "ICPC": "ICPC"
16
+ };
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
+ durationHours: contest.durationSeconds / 60 / 60,
26
+ url: `https://codeforces.com/contests/${contest.id}`
27
+ };
28
+ }).filter(contest => contest.startTime >= new Date());
29
+ }
30
+
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
+ }
67
+ };
68
+ function getGetterList(ojs) {
69
+ if (!ojs) ojs = Object.keys(alloj);
70
+ return ojs.map(oj => alloj[oj].getter);
71
+ }
72
+
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));
75
+ }
76
+
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();
78
+ const opts = commander.program.opts();
79
+
80
+ 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));
82
+ }
83
+
84
+ main();
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "lscontests",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "A CLI tool to get information about the contests on each OJ",
5
+ "keywords": [
6
+ "cli",
7
+ "competitive-programming"
8
+ ],
5
9
  "repository": "https://github.com/StableAgOH/lscontests",
6
10
  "author": "StableAgOH <stagoh17@gmail.com>",
7
11
  "license": "GPL-3.0",
@@ -15,7 +19,8 @@
15
19
  ],
16
20
  "scripts": {
17
21
  "build": "rollup -c",
18
- "watch": "rollup -c --watch"
22
+ "watch": "rollup -c --watch",
23
+ "prepack": "yarn build"
19
24
  },
20
25
  "dependencies": {
21
26
  "axios": "^0.27.2",
@@ -33,9 +38,15 @@
33
38
  "@types/node": "^17.0.31",
34
39
  "@typescript-eslint/eslint-plugin": "^5.22.0",
35
40
  "@typescript-eslint/parser": "^5.22.0",
41
+ "cz-conventional-changelog": "3.3.0",
36
42
  "eslint": "^8.14.0",
37
43
  "rollup": "^2.72.0",
38
44
  "semantic-release": "^19.0.2",
39
45
  "typescript": "^4.6.4"
46
+ },
47
+ "config": {
48
+ "commitizen": {
49
+ "path": "./node_modules/cz-conventional-changelog"
50
+ }
40
51
  }
41
52
  }