-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
58 lines (46 loc) · 2.14 KB
/
worker.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
var twitter = require('twitter');
var util = require('util');
var provider = require(__dirname + '/provider');
var twit = new twitter({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token_key: process.env.ACCESS_TOKEN_KEY,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
});
twit.stream('statuses/filter', {
track: 'found a,found an,found some'
}, function(stream) {
stream.on('data', function(data) {
// Filter out retweets
if (!data.retweeted_status) {
var geoType = null;
var longitude = null;
var latitude = null;
if (data.coordinates && data.coordinates.coordinates) {
geoType = 'coordinate';
if (data.coordinates.coordinates[0]) {
longitude = data.coordinates.coordinates[0];
}
if (data.coordinates.coordinates[1]) {
latitude = data.coordinates.coordinates[1];
}
} else if (data.place && data.place.bounding_box && data.place.bounding_box.coordinates) {
geoType = 'place';
if (data.place.bounding_box.coordinates[0]) {
if (data.place.bounding_box.coordinates[0][0]) {
var longitudeSum = data.place.bounding_box.coordinates[0][0][0] + data.place.bounding_box.coordinates[0][3][0];
var longitude = longitudeSum/2;
}
if (data.place.bounding_box.coordinates[0][3]) {
var latitudeSum = data.place.bounding_box.coordinates[0][0][1] + data.place.bounding_box.coordinates[0][3][1];
var latitude = latitudeSum/2;
}
}
}
// Filter out tweets without geo location
if (geoType && latitude && longitude && data.id_str && data.created_at && data.user.screen_name && data.text) {
provider.add(data.id_str, data.created_at, geoType, data.user.screen_name, data.text, longitude, latitude, data);
}
}
});
});