Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8302593

Browse files
committed
Add -z commend for Chinese columns csv output
�:wq�kb�kbq :q
1 parent cbaf527 commit 8302593

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ Great thanks to leetcode.com, a really awesome website!
1919
[Advanced](https://skygragon.github.io/leetcode-cli/advanced)
2020
[Plugins](https://github.com/skygragon/leetcode-cli-plugins)
2121

22-
* A very <kbd>[**EFFICIENT**](#quick-start)</kbd> way to fight questions.
23-
* <kbd>[**CACHING**](https://skygragon.github.io/leetcode-cli/advanced#cache)</kbd> questions to ease offline thinking.
24-
* <kbd>[**GENERATING**](https://skygragon.github.io/leetcode-cli/commands#show)</kbd> source code before coding.
25-
* Live <kbd>[**TEST**](https://skygragon.github.io/leetcode-cli/commands#test)</kbd> and <kbd>[**SUBMIT**](https://skygragon.github.io/leetcode-cli/commands#submit)</kbd> with leetcode.com.
26-
* Download your previous <kbd>[**SUBMISSION**](https://skygragon.github.io/leetcode-cli/commands#submission)</kbd>.
27-
* Trace your coding <kbd>[**STATUS**](https://skygragon.github.io/leetcode-cli/commands#stat)</kbd>.
28-
* <kbd>[**AUTO LOGIN**](https://skygragon.github.io/leetcode-cli/advanced#auto-login)</kbd> among multiple agents with single account.
29-
* Multiple <kbd>[**THEMES**](https://skygragon.github.io/leetcode-cli/advanced#color-themes)</kbd> support.
30-
* More <kbd>[**PLUGINS**](https://skygragon.github.io/leetcode-cli/advanced#plugins)</kbd> to enjoy extra features!
22+
- A very <kbd>[**EFFICIENT**](#quick-start)</kbd> way to fight questions.
23+
- <kbd>[**CACHING**](https://skygragon.github.io/leetcode-cli/advanced#cache)</kbd> questions to ease offline thinking.
24+
- <kbd>[**GENERATING**](https://skygragon.github.io/leetcode-cli/commands#show)</kbd> source code before coding.
25+
- Live <kbd>[**TEST**](https://skygragon.github.io/leetcode-cli/commands#test)</kbd> and <kbd>[**SUBMIT**](https://skygragon.github.io/leetcode-cli/commands#submit)</kbd> with leetcode.com.
26+
- Download your previous <kbd>[**SUBMISSION**](https://skygragon.github.io/leetcode-cli/commands#submission)</kbd>.
27+
- Trace your coding <kbd>[**STATUS**](https://skygragon.github.io/leetcode-cli/commands#stat)</kbd>.
28+
- <kbd>[**AUTO LOGIN**](https://skygragon.github.io/leetcode-cli/advanced#auto-login)</kbd> among multiple agents with single account.
29+
- Multiple <kbd>[**THEMES**](https://skygragon.github.io/leetcode-cli/advanced#color-themes)</kbd> support.
30+
- More <kbd>[**PLUGINS**](https://skygragon.github.io/leetcode-cli/advanced#plugins)</kbd> to enjoy extra features!
3131

3232
## Personal Change
33+
3334
Add three more features for List command.
35+
3436
1. `-c` to generate .csv format file for all questions. will include companies tag and companies with 3 differnt time period column. Example useage: `leetcode list -c`
37+
- combine '-z' for Chinese column output Example useage: `leetcode list -c -z` (design for better update experience for [Leetcode Spreadsheet](https://docs.google.com/spreadsheets/d/1XFkQJqZlCMitKRnJXEZpWkAx_1dfjbmLG_RkFoz_TPE/edit?usp=sharing))
3538
2. `-o` to set .csv format file output directory. Default directory: `~/.lc`
3639
3. `-p` to filter questions by 3 different time period:
3740
- `1` for questions in recent 0~6 months
@@ -41,8 +44,9 @@ Add three more features for List command.
4144
- Example useage: `leetcode list -t netfilx -p 1`
4245

4346
Add updateData function for Company plugin. function will include following feature.
47+
4448
1. Update company tag if current user is vip user.
45-
2. Will use default value to set company tag if current user is not vip user.(data updated at 2020.06.21)
49+
2. Will use default value to set company tag if current user is not vip user.(data updated at 2021.03.19)
4650
3. Will store current company tags setting in `~/.lc/leetcode/cache/COMPONIES.json` and `~/.lc/leetcode/cache/TAGS.json` and try to update it if the file is missing.
4751

4852
## Screenshot
@@ -51,11 +55,10 @@ Add updateData function for Company plugin. function will include following feat
5155

5256
## Quick Start
5357

54-
Read help first $ leetcode help
55-
Login with your leetcode account $ leetcode user -l
56-
Browse all questions $ leetcode list
57-
Choose one question $ leetcode show 1 -g -l cpp
58-
Coding it!
59-
Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7'
60-
Submit final solution! $ leetcode submit ./two-sum.cpp
61-
58+
Read help first $ leetcode help
59+
Login with your leetcode account $ leetcode user -l
60+
Browse all questions $ leetcode list
61+
Choose one question $ leetcode show 1 -g -l cpp
62+
Coding it!
63+
Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7'
64+
Submit final solution! $ leetcode submit ./two-sum.cpp

lib/commands/list.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var core = require('../core');
99
var file = require('../file');
1010
var session = require('../session');
1111
var path = require('path');
12+
var fs = require('fs');
1213
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
1314

1415
const cmd = {
@@ -36,6 +37,12 @@ const cmd = {
3637
default: path.join(file.homeDir(), 'out.csv'),
3738
describe: 'Target directory for output file'
3839
})
40+
.option('z', {
41+
alias: 'zh',
42+
type: 'boolean',
43+
default: false,
44+
describe: 'Set output csv as chinese column'
45+
})
3946
.option('t', core.filters.tag)
4047
.option('x', {
4148
alias: 'extra',
@@ -79,16 +86,16 @@ cmd.handler = function(argv) {
7986
const csvWriter = createCsvWriter({
8087
path: argv.output,
8188
header: [
82-
{id: 'id', title: 'id'},
83-
{id: 'name', title: 'name'},
84-
{id: 'level', title: 'level'},
85-
{id: 'tags', title: 'tags'},
86-
{id: 'companies', title: 'companies'},
87-
{id: 'companies06', title: 'companies 6 months'},
88-
{id: 'companies612', title: 'companies 6-12 months'},
89-
{id: 'companies1224', title: 'companies 12-24 months'},
90-
{id: 'percent', title: 'percent'},
91-
{id: 'category', title: 'category'},
89+
{id: 'id', title: argv.z ? "题号" : 'id'},
90+
{id: 'name', title: argv.z ? "标题" : 'name'},
91+
{id: 'level', title: argv.z ? "难度" : 'level'},
92+
{id: 'tags', title: argv.z ? "分类" : 'tags'},
93+
{id: 'companies', title: argv.z ? "公司" :'companies'},
94+
{id: 'companies06', title: argv.z ? "6个月内出现" :'companies 6 months'},
95+
{id: 'companies612', title: argv.z ? "一年内出现" :'companies 6-12 months'},
96+
{id: 'companies1224', title: argv.z ? "两年内出现" :'companies 12-24 months'},
97+
{id: 'percent', title: argv.z ? "接受率" : 'percent'},
98+
{id: 'category', title: argv.z ? "类别" : 'category'},
9299
]
93100
});
94101
const stat = {};
@@ -102,6 +109,12 @@ cmd.handler = function(argv) {
102109
if (problem.locked) ++stat.locked;
103110
if (problem.starred) ++stat.starred;
104111

112+
var categoryTrans = {
113+
"algorithms":"算法",
114+
"database":"数据库",
115+
"shell":"命令行"
116+
}
117+
105118
//build data for csvWriter
106119
if(argv.csv){
107120
if(problem.companyStats!=null){
@@ -114,7 +127,7 @@ cmd.handler = function(argv) {
114127
companies612: problem.companyStats["2"].join(','),
115128
companies1224: problem.companyStats["3"].join(','),
116129
percent: problem.percent.toFixed(2),
117-
category: problem.category
130+
category: argv.z ? categoryTrans[problem.category] : problem.category
118131
});
119132
}
120133
else{
@@ -124,7 +137,7 @@ cmd.handler = function(argv) {
124137
tags: problem.tags,
125138
companies: problem.companies,
126139
percent: problem.percent.toFixed(2),
127-
category: problem.category
140+
category: argv.z ? categoryTrans[problem.category] : problem.category
128141
});
129142
}
130143
}
@@ -161,7 +174,11 @@ cmd.handler = function(argv) {
161174
if(argv.csv){
162175
csvWriter
163176
.writeRecords(data)
164-
.then(()=> console.log('The CSV file was written successfully, output path: '+argv.output));
177+
.then(()=> {
178+
fs.writeFileSync(argv.output, '\ufeff' + fs.readFileSync(argv.output));
179+
console.log('The CSV file was written successfully, output path: '+argv.output);
180+
});
181+
165182
}
166183
if (argv.stat) {
167184
log.info();

0 commit comments

Comments
 (0)