-
Notifications
You must be signed in to change notification settings - Fork 0
/
motd.js
33 lines (28 loc) · 925 Bytes
/
motd.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
// Module of the Day randomizer
var qs = require('querystring')
, http = require('http')
, npm = require('npm');
// use API to search npm, randomizing the result I get each time.
var search = process.argv.slice(2).join(' ').trim(); // is pulling the id which is required from the Twitter API
if (!search.length) {
return console.log('\n Usage: node tweets <search term>\n');
}
console.log('\n searching for: \033[96m' + search + '\033[39m\n');
http.request({
host: 'search.twitter.com'
, path: '/search.json?' + qs.stringify({ q:search })
}, function (res) {
var body = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
var obj = JSON.parse(body)
obj.results.forEach(function (tweet) {
console.log(' \033[90m' + tweet.text + '\033[39m');
console.log(' \033[94m' + tweet.from_user + '\033[39m');
console.log('--');
})
})
}).end();