tweetcast/nodejs/node-direct.js
author Raphael Velt <raph.velt@gmail.com>
Fri, 28 Oct 2011 16:46:13 +0200
changeset 340 a99a04556e3b
parent 339 6a073c4a8578
child 341 cab5c9e10f90
permissions -rw-r--r--
Added conversation mode
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     1
/* DEFAULT CONFIGURATION */
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     2
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     3
var TWITTER_USER = 'materiauxnum',
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     4
    TWITTER_PASS = 'm473r14ux7w337',
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     5
    RECORD_NEW_TWEETS = true;
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     6
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
     7
/* CALLING COMMON CONFIGURATION FILE */
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
     8
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
     9
var conf_file = flagOption('-c', 'conf.js');
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    10
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    11
myLog('Reading Configuration from ' + conf_file);
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    12
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    13
var fs = require('fs');
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    14
eval(fs.readFileSync(conf_file,'utf8'));
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    15
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    16
if (typeof sqlfile == "undefined") {
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    17
    sqlfile = __dirname + '/tweets-' + encodeURIComponent(tracking_keyword) + '.sqlite'
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    18
    }
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
    19
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    20
/* FUNCTIONS */
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    21
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    22
function flagOption(flag, defaultValue) {
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    23
    var flagPos = process.argv.indexOf(flag);
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    24
    return ( flagPos != -1 && flagPos < process.argv.length - 1) ? process.argv[flagPos + 1] : defaultValue;
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    25
}
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    26
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    27
function myLog() {
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    28
    var args = ["\033[1;34m["+new Date().toLocaleTimeString()+"]\033[0m"];
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    29
    for (var i in arguments) {
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    30
        args.push(arguments[i]);
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    31
    }
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    32
    console.log.apply(console, args);
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    33
}
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
    34
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    35
function annotationMap(callback, options) {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    36
    var includeDefault = ( options && options.includeDefault ? options.includeDefault : false );
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    37
    var returnObject = ( options && options.returnObject ? options.returnObject : false );
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    38
    res = (returnObject ? {} : []);
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    39
    for (var i in annotations) {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    40
        if (i != "default" || includeDefault) {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    41
            var el = callback(i, annotations[i])
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    42
            if (returnObject) {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    43
                res[i] = el;
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    44
            } else {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    45
                res.push(el);
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    46
            }
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    47
        }
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    48
    }
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    49
    return res;
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    50
}
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    51
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    52
function createTables() {
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    53
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
    54
    var requete = "CREATE TABLE IF NOT EXISTS tweets ( pos INTEGER PRIMARY KEY, tweet_id TEXT UNIQUE, created_at INTEGER, json TEXT" + annotationMap(function(a) { return ', a_' + a + ' INTEGER' }).join("") + " )";
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    55
    db.execute(requete, function(err) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
    56
        if (err) { myLog("SQLITE error",err.stack); }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
    57
        db.execute("CREATE INDEX IF NOT EXISTS idx_created_at ON tweets ( created_at )", function(err) { if (err) { myLog("SQLITE error",err.stack); } });
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    58
    });
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    59
    
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
    60
    db.execute("CREATE TABLE IF NOT EXISTS tweet_refs ( id INTEGER PRIMARY KEY, from_id TEXT, to_id TEXT, ref_type TEXT )", function(err) { if (err) { myLog("SQLITE error",err.stack); } });
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
    61
}
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
    62
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    63
function commitReference(from_id, to_id, ref_type) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    64
    db.execute(
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    65
        "INSERT INTO tweet_refs ( from_id, to_id, ref_type ) VALUES ( ?, ?, ? )",
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    66
        [ from_id, to_id, ref_type ],
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
    67
        function(err) { if (err) { myLog("SQLITE error",err.stack); } }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    68
    );
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
    69
}
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
    70
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    71
function commitTweet(data) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    72
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    73
    var tweet = JSON.parse(data),
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    74
        ann = [];
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    75
    
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    76
    if (!tweet.id) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    77
        myLog("Error: Could not parse data",data);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    78
        return;
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    79
    }
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    80
    
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    81
    try {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    82
        textids(tweet);
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
    83
        for (var j in keys_to_delete) {
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    84
            delete tweet[keys_to_delete[j]];
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
    85
        }
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    86
        textids(tweet.user);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    87
        for (var j in user_keys_to_delete) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    88
            delete tweet.user[user_keys_to_delete[j]];
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    89
        }
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    90
        if (tweet.retweeted_status) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    91
            textids(tweet.retweeted_status);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    92
            for (var j in keys_to_delete) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    93
                delete tweet.retweeted_status[keys_to_delete[j]];
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
    94
            }
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
    95
        }
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    96
        annotationMap(function(i, annotation) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    97
            for (var j in annotation.keywords) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    98
                if (tweet.text.search(annotation.keywords[j]) != -1) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
    99
                    ann.push(i);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   100
                    break;
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   101
                }
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   102
            }
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   103
        });
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   104
        tweet.annotations = ann;
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   105
        tweet.created_at = new Date(tweet.created_at);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   106
//        myLog("Time delta :",(new Date() - tweet.created_at) / 1000);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   107
    } catch (err) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   108
        myLog("Error while processing tweet",err.stack);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   109
    }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   110
    
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   111
    if (tweet.in_reply_to_status_id) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   112
        commitReference( tweet.id, tweet.in_reply_to_status_id, "reply" );
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   113
    }
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   114
    if (tweet.retweeted_status) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   115
        commitReference( tweet.id, tweet.retweeted_status.id, "retweet" );
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   116
    }
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   117
    db.execute(
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   118
        "INSERT INTO tweets ( tweet_id, created_at, json "
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   119
        + annotationMap(function(a) { return ', a_' + a }).join("")
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   120
        + " ) VALUES ( ?, ?, ? "
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   121
        + annotationMap(function(a) { return ', ?' }).join("")
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   122
        + " )",
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   123
        [ tweet.id, tweet.created_at.valueOf(), JSON.stringify(tweet) ].concat(annotationMap(function(a) { return ann.indexOf(a) == -1 ? 0 : 1 })),
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   124
        function(err) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   125
            if (err) { myLog("SQLITE error",err.stack); }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   126
        }
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   127
    );
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   128
}
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   129
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   130
function callBackNewTweets(chunk) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   131
    var newdata = chunk.split('\r\n');
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   132
    for (var i in newdata) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   133
        if (newdata[i].length > 0) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   134
            commitTweet(newdata[i]);
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   135
        }
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   136
    }
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   137
    myLog("Data received - length :",chunk.length);
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   138
}
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   139
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   140
function requestTwitter() {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   141
    myLog("Requesting Twitter to track keyword(s): "+tracking_keyword);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   142
    var req = https.request({
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   143
        host: "stream.twitter.com",
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   144
        path: "/1/statuses/filter.json",
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   145
        method: "POST",
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   146
        headers: {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   147
            'Authorization': 'Basic ' + new Buffer( TWITTER_USER + ":" + TWITTER_PASS ).toString('base64'),
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   148
            'Content-Type': 'application/x-www-form-urlencoded'
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   149
        }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   150
    }, function(res) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   151
        myLog('Reply from stream.twitter.com: ' + res.statusCode);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   152
        myLog('Headers: ' + JSON.stringify(res.headers));
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   153
        res.setEncoding('utf8');
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   154
        res.on('data', callBackNewTweets);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   155
        res.on('end', function() {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   156
            myLog('End Twitter Connection — Trying to reconnect');
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   157
            requestTwitter();
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   158
        });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   159
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   160
    
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   161
    req.write('track=' + encodeURIComponent(tracking_keyword));
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   162
    req.socket.setTimeout(60000);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   163
    req.socket.on('timeout', function() {
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   164
        myLog('TimeOut - Trying to reconnect');
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   165
        requestTwitter();
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   166
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   167
    req.end();
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   168
}
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   169
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   170
function getSendLastPos() {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   171
    db.execute("SELECT MAX(pos) lastpos FROM tweets", function (err, results) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   172
        if (err) { myLog("SQLITE error",err.stack); }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   173
        if (results[0].lastpos != lastpos) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   174
            lastpos = results[0].lastpos ? results[0].lastpos : 0;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   175
//            myLog("Broadcasting last pos = ",lastpos);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   176
            try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   177
                io.sockets.emit('tweetSummary', {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   178
                    tweetcount : lastpos
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   179
                });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   180
            } catch(err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   181
                myLog("SOCKET.IO error while Broadcasting tweetSummary",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   182
            }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   183
        }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   184
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   185
}
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   186
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   187
function getSendTweetPosByDate(date, socket) {
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   188
    db.execute("SELECT pos, created_at, ABS(created_at-" + date + ") AS dist FROM tweets ORDER BY dist ASC LIMIT 0,9", function (err, results) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   189
        if (err) { myLog("SQLITE error",err.stack); }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   190
        if (results.length) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   191
            try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   192
                socket.emit('tweetPosByDate', {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   193
                    tweetpos : results[0].pos,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   194
                    date : results[0].created_at
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   195
                });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   196
            } catch(err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   197
                myLog("SOCKET.IO error while sending tweetPosByDate",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   198
            }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   199
        }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   200
    });
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   201
}
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   202
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   203
function getSendLinkedTweets(pos, socket) {
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   204
//    myLog("request for tweets linked to",pos);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   205
    db.execute("SELECT A.pos pos_a, A.tweet_id id_a, B.pos pos_b, B.tweet_id id_b, ref_type, ABS(B.created_at - A.created_at) delta FROM tweets A, tweets B, tweet_refs WHERE id_a = from_id AND id_b = to_id AND (pos_a = ? OR pos_b = ?) ORDER BY delta ASC LIMIT 0, 10", [ pos, pos ], function(err, results) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   206
        if (err) { myLog("SQLITE error: ",err.stack); }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   207
        var struct = {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   208
            "tweetpos" : pos,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   209
            "referencing" : [],
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   210
            "referenced_by" : []
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   211
        };
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   212
        for (var i in results) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   213
            if (results[i].pos_a == pos) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   214
                struct.referencing.push({
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   215
                    "pos" : results[i].pos_b,
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   216
                    "ref_type" : results[i].ref_type
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   217
                });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   218
            } else {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   219
                struct.referenced_by.push({
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   220
                    "pos" : results[i].pos_a,
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   221
                    "ref_type" : results[i].ref_type
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   222
                });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   223
            }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   224
        }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   225
        try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   226
            socket.emit('linkedTweets', struct);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   227
        } catch(err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   228
            myLog("SOCKET.IO error while sending linkedTweets: ",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   229
        }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   230
    });
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   231
}
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   232
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   233
function getSendTweets(posList, socket) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   234
//    myLog("request for tweets ("+posList.join(',')+") from "+socket.id);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   235
    db.execute("SELECT * FROM tweets WHERE pos IN ( " + posList.join(',') + " )", function (err, results) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   236
        if (err) { myLog("SQLITE error",err.stack); }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   237
        try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   238
            socket.emit('tweets',
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   239
                results.map(function(line) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   240
                    var tw = JSON.parse(line.json);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   241
                    tw.pos = line.pos;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   242
                    return tw;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   243
                })
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   244
            );
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   245
        } catch (err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   246
            myLog("SOCKET.IO error while sending tweets",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   247
        }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   248
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   249
}
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   250
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   251
function getSendTimeline(data, socket) {
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   252
//    myLog("request for timeline (",data.level, data.full,") from "+socket.id);
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   253
    var lvl = date_levels[data.level],
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   254
        requete = "SELECT COUNT(*) AS nb, "
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   255
        + lvl
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   256
        + "*ROUND(created_at/"
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   257
        + lvl
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   258
        + ") AS tranche"
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   259
        + annotationMap(function (a) { return " , SUM(a_" + a + ") AS s_" + a }).join("")
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   260
        + " FROM tweets GROUP BY tranche ORDER BY tranche DESC LIMIT 0," + ( data.full ? "50" : "1" );
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   261
    db.execute(requete, function (err, results) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   262
        if (err) { myLog("SQLITE error",err.stack); }
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   263
        if (!results.length) {
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   264
            return;
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   265
        }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   266
        var tbl = [],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   267
            lastend = parseInt(results[results.length - 1].tranche);
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   268
        for (var i = results.length - 1; i >= 0; i--) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   269
            var start = parseInt(results[i].tranche);
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   270
            while (start > lastend) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   271
                var struct = { "start": lastend, "tweets" : 0, "annotations" : {} };
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   272
                lastend += lvl;
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   273
                struct.end = lastend;
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   274
                tbl.push(struct);
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   275
            }
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   276
            lastend += lvl;
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   277
            var struct = {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   278
                "start" : start,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   279
                "end" : lastend,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   280
                "tweets" : results[i].nb,
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   281
                "annotations" : annotationMap(function (a) {
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   282
                    return results[i]['s_'+a];
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   283
                },{returnObject: true})
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   284
            }
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   285
            tbl.push(struct);
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   286
        }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   287
        try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   288
            socket.emit('timeline', {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   289
                "full" : data.full,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   290
                "level" : data.level,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   291
                "data" : tbl
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   292
            });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   293
        } catch (err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   294
            myLog("SOCKET.IO error while sending timeline",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   295
        }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   296
    });
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
   297
}
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
   298
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   299
function textids(object) {
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   300
    for (var key in object) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   301
        // Workaround for Unicode bug in socket.io.
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   302
        
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   303
        if (typeof object[key] == "string") {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   304
            var tmp = '';
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   305
            for (var i = 0; i < object[key].length; i++) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   306
                tmp += ( object[key].charCodeAt(i) < 128 ? object[key].charAt(i) : "&#" + object[key].charCodeAt(i) + ";" );
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   307
            }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   308
            object[key] = tmp;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   309
        }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   310
        
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   311
        if (key.substr(-2) == 'id') {
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   312
            object[key] = object[key + '_str'];
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   313
            delete object[key + '_str'];
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   314
        }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   315
        
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   316
    }
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   317
}
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   318
332
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   319
function httpHandler(req, res) {
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   320
    myLog("HTTP Request for URL "+req.url);
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   321
    var url = ( req.url == "/config" ? conf_file : __dirname + "/client" + req.url + ( req.url[req.url.length - 1] == "/" ? "index.html" : "" ) );
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   322
    fs.readFile( url, function(err, data) {
332
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   323
        if (err) {
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   324
            myLog("Error 404");
332
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   325
            res.writeHead(404);
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   326
            return res.end('File not found');
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   327
        }
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   328
        res.writeHead(200);
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   329
        res.end(data);
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   330
    });
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   331
}
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   332
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   333
/* Initialization */
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
   334
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   335
var http = require('http'),
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   336
    https = require('https'),
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   337
    sqlite = require('sqlite'),
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   338
    socketio = require('socket.io'),
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   339
    tweets = [],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   340
    lastpos = 0,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   341
    arcs = [],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   342
    tweet_ids = [],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   343
    date_struct = [],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   344
    date_levels = [
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   345
        3600 * 1000,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   346
        15 * 60 * 1000,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   347
        5 * 60 * 1000,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   348
        60 * 1000,
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   349
        15 * 1000
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   350
    ],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   351
    keys_to_delete = [
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   352
        'in_reply_to_screen_name',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   353
        'in_reply_to_user_id',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   354
        'retweeted',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   355
        'place',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   356
        'geo',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   357
        'source',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   358
        'contributors',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   359
        'coordinates',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   360
        'retweet_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   361
        'favorited',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   362
        'truncated',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   363
        'possibly_sensitive'
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   364
    ],
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   365
    user_keys_to_delete = [
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   366
        'default_profile_image',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   367
        'show_all_inline_media',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   368
        'contributors_enabled',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   369
        'profile_sidebar_fill_color',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   370
        'created_at',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   371
        'lang',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   372
        'time_zone',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   373
        'profile_sidebar_border_color',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   374
        'follow_request_sent',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   375
        'profile_background_image_url',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   376
        'profile_background_image_url_https',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   377
        'followers_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   378
        'description',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   379
        'url',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   380
        'geo_enabled',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   381
        'profile_use_background_image',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   382
        'default_profile',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   383
        'following',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   384
        'profile_text_color',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   385
        'is_translator',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   386
        'favourites_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   387
        'listed_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   388
        'friends_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   389
        'profile_link_color',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   390
        'protected',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   391
        'location',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   392
        'notifications',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   393
        'profile_image_url_https',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   394
        'statuses_count',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   395
        'verified',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   396
        'profile_background_color',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   397
        'profile_background_tile',
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   398
        'utc_offset'
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   399
    ],
332
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   400
    app = http.createServer(httpHandler),
738594562e44 Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents: 331
diff changeset
   401
    io = socketio.listen(app),
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   402
    db = new sqlite.Database();
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   403
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   404
/* MAIN CODE */
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   405
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   406
app.listen(app_port);
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   407
myLog("Listening on port: "+app_port);
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   408
myLog("Opening SQLITE file: "+sqlfile);
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   409
db.open(sqlfile , function(err) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   410
    if (err) { myLog("SQLITE error",err.stack); }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   411
    createTables();
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   412
});
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   413
340
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   414
setInterval(getSendLastPos,300);
a99a04556e3b Added conversation mode
Raphael Velt <raph.velt@gmail.com>
parents: 339
diff changeset
   415
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
   416
if (RECORD_NEW_TWEETS) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   417
    requestTwitter();
325
7d9c576bfaac Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents: 314
diff changeset
   418
}
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   419
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   420
io.set('log level', 0);
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   421
io.sockets.on('connection', function(socket) {
338
60dff8a71024 Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents: 335
diff changeset
   422
    myLog("New connection from", socket.handshake.address.address, "with id=", socket.id);
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   423
    try {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   424
        socket.emit('tweetSummary', { tweetcount : lastpos });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   425
    } catch (err) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   426
        myLog("SOCKET.IO error while sending tweetSummary",err.stack);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   427
    }
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   428
    socket.on('updateTweets', function(data) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   429
        if (data.tweets.length) {
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   430
            getSendTweets(data.tweets, socket);
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   431
        }
326
c28048fb63b4 Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents: 325
diff changeset
   432
    });
331
03c69425efa6 Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents: 326
diff changeset
   433
    socket.on('updateTimeline', function(data) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   434
        getSendTimeline(data, socket);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   435
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   436
    socket.on('tweetPosByDate', function(data) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   437
        getSendTweetPosByDate(data.date, socket);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   438
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   439
    socket.on('linkedTweets', function(data) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 338
diff changeset
   440
        getSendLinkedTweets(data.tweetpos, socket);
314
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   441
    });
0f1e6ce19b6d Ajout d une branche NodeJS
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   442
});