-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
31 lines (30 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env node
const request = require('request');
const chalk = require('chalk');
const Table = require('cli-table');
const requestUrl = 'https://coooins.com/api/subreddits';
request(requestUrl, function (error, response, body) {
const data = JSON.parse(body);
const totalMessage = `Total Subreddits: ` + data.total_subreddits + ` Total Subscribers: ` + data.total_subscribers + ` Total Online: ` + data.total_online;
console.log(chalk.blue(totalMessage));
const table = new Table({ head: [
chalk.blue('Name'),
chalk.blue('Subreddit'),
chalk.blue('URL'),
chalk.blue('Subscribers'),
chalk.blue('Online'),
chalk.blue('Last Updated'),
] });
data.subreddits.forEach(function (value, key) {
table.push([
chalk.blue(value.name),
chalk.green(value.subreddit),
chalk.green(value.subreddit_url),
chalk.green(Number(value.subscribers).toLocaleString('en')),
chalk.green(Number(value.online).toLocaleString('en')),
chalk.green(value.last_updated),
]);
});
console.log('\n'+table.toString());
console.log(chalk.blue(totalMessage));
});