-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·60 lines (51 loc) · 1.51 KB
/
cli.js
File metadata and controls
executable file
·60 lines (51 loc) · 1.51 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
'use strict';
const dns = require('dns');
const got = require('got');
const cheerio = require('cheerio');
const logUpdate = require('log-update');
const ora = require('ora');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');
updateNotifier({pkg}).notify();
const arg = process.argv[2];
const spinner = ora();
if (!arg) {
console.log(`
Usage: twifo <user-name>
Example:
$ twifo 9gag
`);
process.exit(1);
}
dns.lookup('twitter.com', err => {
if (err) {
logUpdate(`\n› Please check your internet connection\n`);
process.exit(1);
} else {
logUpdate();
spinner.text = `Twifing ${arg}`;
spinner.start();
}
});
const url = `https://twitter.com/${arg}`;
got(url).then(res => {
const $ = cheerio.load(res.body);
logUpdate(`
› Name : ${$('.ProfileHeaderCard-nameLink').text()}
› Handle : ${$('.ProfileHeaderCard-screennameLink').text().trim()}
› Biography : ${$('.ProfileHeaderCard-bio').text()}
› Place : ${$('.ProfileHeaderCard-locationText').text().trim()}
› Joined : ${$('.ProfileHeaderCard-joinDateText').text().trim().replace('Joined', '').trim()}
› Tweets : ${$('.ProfileNav-value').eq(0).text().trim()}
› Following : ${$('.ProfileNav-value').eq(1).text().trim()}
› Follwers : ${$('.ProfileNav-value').eq(2).text().trim()}
› Likes : ${$('.ProfileNav-value').eq(3).text().trim()}
`);
spinner.stop();
}).catch(err => {
if (err) {
logUpdate(`\n› ${arg} is not a Twitter user\n`);
process.exit(1);
}
});