-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.37 KB
/
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
40
41
42
43
44
45
46
47
48
var express = require('express');
var app = express();
var mecab = require('mecab-ffi');
var server = require('http').createServer(app);
var tuiter = require('tuiter');
var keys = require('./keys');
var tu = tuiter(keys);
var io = require('engine.io').attach(server);
var opener = require('opener');
app.set('port', process.env.PORT || 3000);
app.use(express.static(__dirname + '/public'));
io.on('connection', function (socket) {
console.log("connection");
tu.search({q:'#de04'}, function(error, tweet){
if(error) throw error;
var num = tweet["statuses"].length;
for(var k=0; k<num; k++) {
mecab.parse(tweet["statuses"][k].text, function(err, result) {
//console.log(err, result, tweet.text);
tweet.segments = result;
Object.keys(io.clients).forEach(function(key) {
io.clients[key].send(JSON.stringify(tweet));
});
});
}
});
});
tu.filter({ track: ['#de04'] }, function(stream) {
stream.on('tweet', function(tweet) {
mecab.parse(tweet.text, function(err, result) {
// console.log(err, result, tweet.text);
tweet.segments = result;
Object.keys(io.clients).forEach(function(key) {
io.clients[key].send(JSON.stringify(tweet));
});
});
});
});
server.listen(app.get('port'), function() {
console.log('listening in port %s', app.get('port'));
opener('http://localhost:' + app.get('port') + '/');
});