-
Notifications
You must be signed in to change notification settings - Fork 0
/
alden.js
92 lines (76 loc) · 2.22 KB
/
alden.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// **************************
// ****** DEPENDENCIES ******
// **************************
var tm = require('./analysis/twelpMap');
var twitter = require('./api/twitterApi');
var proc = require('./util/process');
var _ = require('lodash');
var database = require('./api/database');
var lazy = require('lazy');
var fs = require('fs');
// **************************
// ******** PROGRAM ********
// **************************
var fromFile = './private/yelp/20140321_businesses.json';
new lazy(fs.createReadStream(fromFile))
.lines
.map(function(line) { return JSON.parse(line.toString()); })
.take(10)
.forEach(function(biz) {
biz.reviews = [];
console.log(JSON.stringify(biz, null, 2));
});
return;
var fromFile = './private/tweets.json';
new lazy(fs.createReadStream(fromFile))
.lines
.map(function(line) { return line.toString(); })
.forEach(function(line) {
var tweet = JSON.parse(line.toString());
if (tweet.coordinates && tweet.coordinates.coordinates && tweet.coordinates.coordinates.length > 0) {
console.log(JSON.stringify(tweet.coordinates.coordinates));
}
})
.join(function() {
proc.done('DONE');
});
return;
// count number of foursquare checkins
database.runWithConn(function() {
database.findTweets({}, function(err, tweets) {
if (err) { proc.bail('Failed to find tweets', err); }
var matchingTweets = _.filter(tweets, function(tweet) {
return tweet.urls && _.any(tweet.urls, function(url) {
return url.toLowerCase().indexOf('foursquare') != -1;
});
});
console.log(matchingTweets.length);
proc.done();
});
});
return;
// count tweets/sec in NYC
var start = new Date();
var count = 0;
var NYC = [ '-74', '40', '-73', '41' ];
twitter.startStream({locations: NYC}, function(tweet) {
count++;
if (count % 10 == 0) {
var elapsed = new Date() - start;
console.log(count + " tweets, " + elapsed/1000 + " s");
}
});
return;
// analyze twelp
tm.analyzeTwelpMap(function(err, res) {
if (err) {
proc.bail('', err);
}
console.log('TOTAL BIZS : ' + res.bizs);
console.log('WITH SITES : ' + res.withSite);
console.log('WITH TWITTER : ' + res.withTwitter);
console.log('TWITTER DUPS : ' + res.dupUsernames);
console.log('GOOD TWITTER : ' + res.goodUsernames);
proc.done();
});
return;