-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (46 loc) · 1.3 KB
/
server.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
// Librairies
var express = require('express'),
app = express.createServer();
var http = require('http'),
config = require('./config')();
app.configure(function () {
});
app.listen(config.appPort);
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: config.twitterApiKey,
consumer_secret: config.twitterSecret,
access_token_key: config.twitterAccessToken,
access_token_secret: config.twitterAccessSecret
});
console.log(client);
var params = {screen_name: '@letsGoChatHere'};
client.stream('statuses/filter', {track: '@letsGoChatHere'}, function(stream) {
console.log("Stream start");
stream.on('data', function(tweet) {
var jsonTweet = JSON.stringify(tweet);
var post_options = {
host: 'localhost',
port: '4444',
path: '/api/discussions',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': jsonTweet.length
}
};
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// post the data
post_req.write(jsonTweet);
post_req.end();
});
stream.on('error', function(error) {
console.log(error);
throw error;
});
});