Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmds/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ const getStock = async (args) => {

spinner.stop()
// clear()
console.log(tabulate(['名称', '代码', '最新', '涨幅']))
var date = new Date();
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() < 10 ? '0'+(date.getDate())+'T' : date.getDate()+'T';
h = date.getHours() < 10 ? '0'+(date.getHours())+':' : date.getHours()+':';
m = date.getMinutes() < 10 ? '0'+(date.getMinutes())+':' : date.getMinutes()+':';
s = date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds();
console.log(Y+M+D+h+m+s);
// console.log(tabulate(['名称', '代码', '最新', '涨幅']))
console.log(tabulate(['名称', '代码', '最新', '涨幅', '成交量']))
stocks.forEach((item, index) => {
const stockInfo = parse(codes[index], item)

Expand All @@ -44,4 +53,4 @@ const getStock = async (args) => {
}
}

module.exports = getStock
module.exports = getStock
49 changes: 41 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
{
"name": "stocki",
"version": "1.0.2",
"main": "index.js",
"author": "liu",
"license": "MIT",
"_from": "stocki",
"_id": "stocki@1.0.2",
"_inBundle": false,
"_integrity": "sha512-JleN4EeEfdbie0jms02NR2NKUF0b1xYV/5gjp2qQcNYDCi4+zS9U/pjgSHEOfC8jR8ac1zMbZH5N2UheVl9RFQ==",
"_location": "/stocki",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "stocki",
"name": "stocki",
"escapedName": "stocki",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/stocki/-/stocki-1.0.2.tgz",
"_shasum": "2920a57ef4276695e1b03dc16badfe358fd3d6fe",
"_spec": "stocki",
"_where": "/usr/lib/node_modules/stocki/bin",
"author": {
"name": "liu"
},
"bin": {
"stock": "bin/stock"
},
"bugs": {
"url": "https://github.com/jeezliu/stock-cli/issues"
},
"bundleDependencies": false,
"dependencies": {
"axios": "^0.19.0",
"chalk": "^2.4.2",
"configstore": "^5.0.0",
"iconv-lite": "^0.5.0",
"minimist": "^1.2.3",
"minimist": "^1.2.0",
"ora": "^3.4.0",
"word-width": "^1.0.1"
},
"deprecated": false,
"description": "Stocki 命令行程序查看股票价格。关注股票后,stock star 命令即可打印出关注股票的最新价格。",
"homepage": "https://github.com/jeezliu/stock-cli#readme",
"license": "MIT",
"main": "index.js",
"name": "stocki",
"repository": {
"type": "git",
"url": "https://github.com/jeezliu/stock-cli"
}
"url": "git+https://github.com/jeezliu/stock-cli.git"
},
"version": "1.0.2"
}
3 changes: 2 additions & 1 deletion utils/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = async (codes = []) => {
const results = await axios({
method: 'get',
url: 'http://hq.sinajs.cn/list=' + codes.join(','),
headers: {Referer: 'https://www.sina.com.cn'},
responseType: 'stream'
})

Expand All @@ -24,4 +25,4 @@ module.exports = async (codes = []) => {
resolve(resArr)
})
})
}
}
6 changes: 4 additions & 2 deletions utils/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = (code, info) => {
const last = arr[2]
const now = arr[3]
const change = ((now - last) / last) * 100
return [name, code, now, change.toFixed(2)]
//return [name, code, now, change.toFixed(2)]
const number = arr[8]/1000000
return [name, code, now, change.toFixed(2), number.toFixed(2)+'万手']
}
if(code.startsWith('hk')) {
const name = arr[1]
Expand All @@ -21,4 +23,4 @@ module.exports = (code, info) => {
return [name, code, now, change]
}
return ['', code, '', '']
}
}