-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.js
48 lines (36 loc) · 980 Bytes
/
twitter.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 https = require("https");
var options = {
host:"stream.twitter.com",
port:"/1/statuses/filter.json?track=bieber",
method:"GET",
headers:{
"Authorization":"Basic"+ new Buffer("username:password").toString("base64")
}
};
var twitterCollection;
var mongo = require("mongodb");
var host = "127.0.0.1";
var post = mongo.Connection.DEFAULT_PORT;
var db = new mongo.DB("nodejs twitter",new mongo.Server(host,port,{}));
db.open(function(error){
console.log("db opened");
db.collection("twitter",function(error,collection){
twitterCollection = collection;
});
});
var request = https.request(options,function(response){
response.on("data",function(chunk){
var tweet = JSON.parse(chunk);
twitterCollection.insert(tweet,function(error){
if(error){
console.log(error);
} else {
console.log("inserted successfully");
}
});
});
response.on("end",function(){
console.log("disconnected");
})
});
response.end();