-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchTwitter.js
54 lines (43 loc) · 1.32 KB
/
searchTwitter.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// **************************
// ****** DEPENDENCIES ******
// **************************
var _ = require('lodash');
var twitter = require('./api/twitterApi');
var logger = require('./util/log').getFileLogger('poison-search');
var proc = require('./util/process');
// **************************
// ******** PROCESS *********
// **************************
var queries = _.rest(process.argv, 2);
// **************************
// ****** PROGRAM ******
// **************************
serializeQs = function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
};
var allTweets = {};
_.each(queries, function(query) {
var searchParam = {
q: query,
count: 100,
lang: 'en',
result_type: 'recent',
include_entities: 1,
geocode: '40.6700,-73.9400,13mi'
};
// kick off search
twitter.search(serializeQs(searchParam), function(err, tweets) {
if (err) { proc.bail('Twitter API failed!', err); }
console.log('Query \'' + query + '\' returned ' + tweets.length + ' tweets');
_.each(tweets, function(tweet) {
if (!allTweets[tweet.id]) {
allTweets[tweet.id] = tweet;
logger.info(tweet);
}
});
console.log('Total ' + _.values(allTweets).length + ' tweets');
});
});