UNPKG

fund-cli

Version:
88 lines (82 loc) 3.17 kB
#!/usr/bin/env node var program = require('commander') var trending = require('./lib/trending') let Table = require('tty-table') const chalk = require('chalk'); const moment = require('moment') program .arguments('<cmd> [date]') .action(function(cmd, date) { date = date || moment().format('YYYY-MM-DD') trending.show({ date }).then((res) => { const { code, result } = res const { total, upTotal, downTotal, upTopFunds, downTopFunds } = result const fairTotal = total - upTotal - downTotal var upTopFundsTable = new Table([{ value: '基金代号', width: 10 }, { value: '基金名称', width: 35 }, { value: '基金净值', width: 10 }, { value: '基金现值', width: 10 }, { value: '日涨幅(%)', width: 12, formatter: function(value) { return chalk.red(value) } } ]) upTopFunds.map((item) => { const { code, name, netValue, cumulativeNetValue, dailyGrowthRate } = item upTopFundsTable.push([code, name, netValue, cumulativeNetValue, dailyGrowthRate]) }) console.log(upTopFundsTable.render()); var downTopFundsTable = new Table([{ value: '基金代号', width: 10 }, { value: '基金名称', width: 35 }, { value: '基金净值', width: 10 }, { value: '基金现值', width: 10 }, { value: '日跌幅(%)', width: 12, formatter: function(value) { return chalk.green(value) } } ]) downTopFunds.map((item) => { const { code, name, netValue, cumulativeNetValue, dailyGrowthRate } = item downTopFundsTable.push([code, name, netValue, cumulativeNetValue, dailyGrowthRate]) }) console.log(downTopFundsTable.render()) let emoji = '😭' if (upTotal > downTotal) { emoji = '😀' } console.log(' --------------------------------------------------------------------------------------- ') console.log(` | ${emoji} 基金总数:${total} | 上涨总数: ⬆️ ${chalk.red(upTotal)} | 下跌总数: ⬇️ ${chalk.green(downTotal)} | 持平总数:${fairTotal} |`) console.log(' --------------------------------------------------------------------------------------- ') }) }) program.parse(process.argv)