source: trip-planner-front/node_modules/jsonparse/examples/twitterfeed.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1003 bytes
RevLine 
[6a3a178]1var Parser = require('../jsonparse');
2var Http = require('http');
3require('./colors');
4var p = new Parser();
5var cred = require('./credentials');
6var client = Http.createClient(80, "stream.twitter.com");
7var request = client.request("GET", "/1/statuses/sample.json", {
8 "Host": "stream.twitter.com",
9 "Authorization": (new Buffer(cred.username + ":" + cred.password)).toString("base64")
10});
11request.on('response', function (response) {
12 console.log(response.statusCode);
13 console.dir(response.headers);
14 response.on('data', function (chunk) {
15 p.write(chunk);
16 });
17 response.on('end', function () {
18 console.log("END");
19 });
20});
21request.end();
22var text = "", name = "";
23p.onValue = function (value) {
24 if (this.stack.length === 1 && this.key === 'text') { text = value; }
25 if (this.stack.length === 2 && this.key === 'name' && this.stack[1].key === 'user') { name = value; }
26 if (this.stack.length === 0) {
27 console.log(text.blue + " - " + name.yellow);
28 text = name = "";
29 }
30};
Note: See TracBrowser for help on using the repository browser.