-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (30 loc) · 835 Bytes
/
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
32
33
34
35
36
37
38
39
'use strict';
const _ = require('lodash'),
Promise = require('bluebird'),
timeline = require('./timeline'),
followRedirect = require('./redirect');
if (process.argv.length < 3) {
console.log('Please specify a username');
process.exit(1);
}
const screenName = process.argv[2];
const getTweets = (timeline) => _.map(timeline, 'text');
function extractUrls(tweets) {
const urlMatches = (tweet) => tweet.match(/https?:\/\/[^ ]+/g);
return _(tweets)
.map(urlMatches)
.filter()
.flatten()
.value();
}
function followRedirects(links) {
return Promise.map(links, followRedirect);
}
function printUrls(urls) {
console.dir(urls, { colors: true });
}
timeline.get(screenName)
.then(getTweets)
.then(extractUrls)
.then(followRedirects)
.then(printUrls);