diff --git a/cmds/get.js b/cmds/get.js index 6f740d3..12403a8 100644 --- a/cmds/get.js +++ b/cmds/get.js @@ -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) @@ -44,4 +53,4 @@ const getStock = async (args) => { } } -module.exports = getStock \ No newline at end of file +module.exports = getStock diff --git a/package.json b/package.json index 4ac950e..71deb3f 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/utils/fetch.js b/utils/fetch.js index 15587ea..743611b 100644 --- a/utils/fetch.js +++ b/utils/fetch.js @@ -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' }) @@ -24,4 +25,4 @@ module.exports = async (codes = []) => { resolve(resArr) }) }) -} \ No newline at end of file +} diff --git a/utils/parse.js b/utils/parse.js index a0c96be..863db8e 100644 --- a/utils/parse.js +++ b/utils/parse.js @@ -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] @@ -21,4 +23,4 @@ module.exports = (code, info) => { return [name, code, now, change] } return ['', code, '', ''] -} \ No newline at end of file +}