--- a/tweetcast/nodejs-bis/tweetcast.js Tue Nov 15 11:38:14 2011 +0100
+++ b/tweetcast/nodejs-bis/tweetcast.js Tue Nov 15 18:29:44 2011 +0100
@@ -6,7 +6,7 @@
eval(fs.readFileSync(conf_file,'utf8'));
tweet_file = flagOption('-f', (typeof tweet_file == "undefined" ? 'tweets.txt' : tweet_file ));
-tracking_keyword = flagOption('-t', (typeof tracking_keyword == "undefined" ? null : tracking_keyword ));
+tracking_keyword = flagOption('-t', (typeof tracking_keywords == "undefined" ? null : tracking_keywords.join(",") ));
user_pass = flagOption('-u', (typeof user_pass == "undefined" ? null : user_pass ));
if (!user_pass) {
@@ -75,18 +75,27 @@
'profile_background_color',
'profile_background_tile',
'utc_offset'
- ];
+ ],
+ content_types = {
+ css : "text/css",
+ html : "text/html",
+ js : "text/javascript",
+ png : "image/png"
+ };
function httpHandler(req, res) {
console.log("HTTP Request for URL "+req.url);
- var url = ( req.url == "/config" ? conf_file : __dirname + "/client" + req.url + ( req.url[req.url.length - 1] == "/" ? "index.html" : "" ) );
+ var url = ( req.url == "/config" ? conf_file : __dirname + "/client" + req.url + ( req.url[req.url.length - 1] == "/" ? "index.html" : "" ) ),
+ ext = url.split('.').slice(-1)[0].toLowerCase();
fs.readFile( url, function(err, data) {
if (err) {
console.log("Error 404");
res.writeHead(404);
return res.end('File not found');
}
- res.writeHead(200);
+ res.writeHead(200, {
+ "Content-Type" : ( content_types[ext] ? content_types[ext] : 'text/plain' )
+ });
res.end(data);
});
}
@@ -101,6 +110,7 @@
console.log("Error: Tweet already in list");
return false;
}
+ tweet.date_value = new Date(tweet.created_at).valueOf();
tweets.push(tweet);
tweet_ids.push(tweet.id);
return true;
@@ -163,19 +173,7 @@
try {
for (var i in newdata) {
if (newdata[i].length > 0) {
- var tweet = JSON.parse(newdata[i]),
- ann = [];
- for (var j in annotations) {
- if (j != "default") {
- for (var k in annotations[j].keywords) {
- if (tweet.text.search(annotations[j].keywords[k]) != -1) {
- ann.push(j);
- break;
- }
- }
- }
- }
- tweet.annotations = ann;
+ var tweet = JSON.parse(newdata[i]);
textids(tweet);
for (var j in keys_to_delete) {
delete tweet[keys_to_delete[j]];
@@ -206,7 +204,7 @@
});
});
- req.write('track=' + encodeURIComponent((tracking_keyword)));
+ req.write('track=' + encodeURIComponent( ( tracking_keyword ) ) );
req.end();
}