| author | Raphael Velt <raph.velt@gmail.com> |
| Thu, 27 Oct 2011 17:57:53 +0200 | |
| changeset 339 | 6a073c4a8578 |
| parent 338 | 60dff8a71024 |
| child 340 | a99a04556e3b |
| permissions | -rw-r--r-- |
|
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 | 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 |
getSendLastPos(); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
59 |
}); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
60 |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
61 |
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
|
62 |
} |
|
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
63 |
|
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
64 |
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
|
65 |
db.execute( |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
66 |
"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
|
67 |
[ from_id, to_id, ref_type ], |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
68 |
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
|
69 |
); |
|
325
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
70 |
} |
|
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
71 |
|
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
72 |
function commitTweet(data) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
73 |
|
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
74 |
var tweet = JSON.parse(data), |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
75 |
ann = []; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
76 |
|
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
77 |
textids(tweet); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
78 |
for (var j in keys_to_delete) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
79 |
delete tweet[keys_to_delete[j]]; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
80 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
81 |
textids(tweet.user); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
82 |
for (var j in user_keys_to_delete) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
83 |
delete tweet.user[user_keys_to_delete[j]]; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
84 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
85 |
if (tweet.retweeted_status) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
86 |
textids(tweet.retweeted_status); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
87 |
for (var j in keys_to_delete) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
88 |
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
|
89 |
} |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
90 |
} |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
91 |
annotationMap(function(i, annotation) { |
|
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
92 |
for (var j in annotation.keywords) { |
|
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
93 |
if (tweet.text.search(annotation.keywords[j]) != -1) { |
|
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
94 |
ann.push(i); |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
95 |
break; |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
96 |
} |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
97 |
} |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
98 |
}); |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
99 |
tweet.annotations = ann; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
100 |
tweet.created_at = new Date(tweet.created_at); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
101 |
|
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
102 |
if (tweet.in_reply_to_status_id) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
103 |
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
|
104 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
105 |
if (tweet.retweeted_status) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
106 |
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
|
107 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
108 |
db.execute( |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
109 |
"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
|
110 |
+ 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
|
111 |
+ " ) VALUES ( ?, ?, ? " |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
112 |
+ annotationMap(function(a) { return ', ?' }).join("") |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
113 |
+ " )", |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
114 |
[ 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
|
115 |
function(err) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
116 |
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
|
117 |
getSendLastPos(); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
118 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
119 |
); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
120 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
121 |
|
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
122 |
function callBackNewTweets(chunk) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
123 |
var newdata = chunk.split('\r\n'); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
124 |
for (var i in newdata) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
125 |
if (newdata[i].length > 0) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
126 |
commitTweet(newdata[i]); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
127 |
} |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
128 |
} |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
129 |
// myLog("New tweets received"); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
130 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
131 |
|
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
132 |
function requestTwitter() { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
133 |
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
|
134 |
var req = https.request({ |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
135 |
host: "stream.twitter.com", |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
136 |
path: "/1/statuses/filter.json", |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
137 |
method: "POST", |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
138 |
headers: { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
139 |
'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
|
140 |
'Content-Type': 'application/x-www-form-urlencoded' |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
141 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
142 |
}, function(res) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
143 |
myLog('Reply from stream.twitter.com: ' + res.statusCode); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
144 |
myLog('Headers: ' + JSON.stringify(res.headers)); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
145 |
res.setEncoding('utf8'); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
146 |
res.on('data', callBackNewTweets); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
147 |
res.on('end', function() { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
148 |
myLog('End Twitter Connection — Trying to reconnect'); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
149 |
requestTwitter(); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
150 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
151 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
152 |
|
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
153 |
req.write('track=' + encodeURIComponent(tracking_keyword)); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
154 |
req.socket.setTimeout(60000); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
155 |
req.socket.on('timeout', function() { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
156 |
myLog('TimeOut — 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 |
req.end(); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
160 |
} |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
161 |
|
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
162 |
function getSendLastPos() { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
163 |
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
|
164 |
if (err) { myLog("SQLITE error",err.stack); } |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
165 |
if (results[0].lastpos != lastpos) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
166 |
lastpos = results[0].lastpos ? results[0].lastpos : 0; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
167 |
// myLog("Broadcasting last pos = ",lastpos); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
168 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
169 |
io.sockets.emit('tweetSummary', { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
170 |
tweetcount : lastpos |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
171 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
172 |
} catch(err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
173 |
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
|
174 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
175 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
176 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
177 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
178 |
|
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
179 |
function getSendTweetPosByDate(date, socket) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
180 |
db.execute("SELECT pos, created_at, ABS(created_at-" + date + ") AS dist FROM tweets ORDER BY dist ASC LIMIT 0,1", function (err, results) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
181 |
if (err) { myLog("SQLITE error",err.stack); } |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
182 |
if (results.length) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
183 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
184 |
socket.emit('tweetPosByDate', { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
185 |
tweetpos : results[0].pos, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
186 |
date : results[0].created_at |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
187 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
188 |
} catch(err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
189 |
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
|
190 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
191 |
} |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
192 |
}); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
193 |
} |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
194 |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
195 |
function getSendLinkedTweets(pos, socket) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
196 |
myLog("request for tweets linked to",pos); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
197 |
db.execute("SELECT A.pos pos_a, A.tweet_id id_a, A.json json_a, B.pos pos_b, B.tweet_id id_b, B.json json_b, ref_type FROM tweets A, tweets B, tweet_refs WHERE id_a = from_id AND id_b = to_id AND (pos_a = ? OR pos_b = ?)", [ pos, pos ], function(err, results) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
198 |
if (err) { myLog("SQLITE error: ",err.stack); } |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
199 |
var struct = { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
200 |
"tweetpos" : pos, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
201 |
"referencing" : [], |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
202 |
"referenced_by" : [] |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
203 |
}; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
204 |
for (var i in results) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
205 |
if (results[i].pos_a == pos) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
206 |
var tw = JSON.parse(results[i].json_b); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
207 |
tw.pos = results[i].pos_b; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
208 |
struct.referencing.push({ |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
209 |
"tweet" : tw, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
210 |
"ref_type" : results[i].ref_type |
|
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 |
} else { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
213 |
var tw = JSON.parse(results[i].json_a); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
214 |
tw.pos = results[i].pos_a; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
215 |
struct.referenced_by.push({ |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
216 |
"tweet" : tw, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
217 |
"ref_type" : results[i].ref_type |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
218 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
219 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
220 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
221 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
222 |
socket.emit('linkedTweets', struct); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
223 |
} catch(err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
224 |
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
|
225 |
} |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
226 |
}); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
227 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
228 |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
229 |
function getSendTweets(posList, socket) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
230 |
// 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
|
231 |
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
|
232 |
if (err) { myLog("SQLITE error",err.stack); } |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
233 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
234 |
socket.emit('tweets', |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
235 |
results.map(function(line) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
236 |
var tw = JSON.parse(line.json); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
237 |
tw.pos = line.pos; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
238 |
return tw; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
239 |
}) |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
240 |
); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
241 |
} catch (err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
242 |
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
|
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 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
246 |
|
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
247 |
function getSendTimeline(data, socket) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
248 |
myLog("request for timeline (",data.level, data.full,") from "+socket.id); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
249 |
var lvl = date_levels[data.level], |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
250 |
requete = "SELECT COUNT(*) AS nb, " |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
251 |
+ lvl |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
252 |
+ "*ROUND(created_at/" |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
253 |
+ lvl |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
254 |
+ ") AS tranche" |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
255 |
+ 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
|
256 |
+ " 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
|
257 |
db.execute(requete, function (err, results) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
258 |
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
|
259 |
var tbl = [], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
260 |
lastend = parseInt(results[results.length - 1].tranche); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
261 |
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
|
262 |
var start = parseInt(results[i].tranche); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
263 |
while (start > lastend) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
264 |
var struct = { "start": lastend, "tweets" : 0, "annotations" : {} }; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
265 |
lastend += lvl; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
266 |
struct.end = lastend; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
267 |
tbl.push(struct); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
268 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
269 |
lastend += lvl; |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
270 |
var struct = { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
271 |
"start" : start, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
272 |
"end" : lastend, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
273 |
"tweets" : results[i].nb, |
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
274 |
"annotations" : annotationMap(function (a) { |
|
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
275 |
return results[i]['s_'+a]; |
|
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
276 |
},{returnObject: true}) |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
277 |
} |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
278 |
tbl.push(struct); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
279 |
} |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
280 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
281 |
socket.emit('timeline', { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
282 |
"full" : data.full, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
283 |
"level" : data.level, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
284 |
"data" : tbl |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
285 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
286 |
} catch (err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
287 |
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
|
288 |
} |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
289 |
}); |
|
325
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
290 |
} |
|
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
291 |
|
| 314 | 292 |
function textids(object) { |
293 |
for (var key in object) { |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
294 |
// Workaround for Unicode bug in socket.io. |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
295 |
|
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
296 |
if (typeof object[key] == "string") { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
297 |
var tmp = ''; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
301 |
object[key] = tmp; |
|
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 |
|
| 314 | 304 |
if (key.substr(-2) == 'id') { |
305 |
object[key] = object[key + '_str']; |
|
306 |
delete object[key + '_str']; |
|
307 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
308 |
|
| 314 | 309 |
} |
310 |
} |
|
311 |
||
|
332
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
312 |
function httpHandler(req, res) { |
|
338
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
313 |
myLog("HTTP Request for URL "+req.url); |
|
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
314 |
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
|
315 |
fs.readFile( url, function(err, data) { |
|
332
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
316 |
if (err) { |
|
338
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
317 |
myLog("Error 404"); |
|
332
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
318 |
res.writeHead(404); |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
319 |
return res.end('File not found'); |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
320 |
} |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
321 |
res.writeHead(200); |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
322 |
res.end(data); |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
323 |
}); |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
324 |
} |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
325 |
|
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
326 |
/* Initialization */ |
|
325
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
327 |
|
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
328 |
var http = require('http'), |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
329 |
https = require('https'), |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
330 |
sqlite = require('sqlite'), |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
331 |
socketio = require('socket.io'), |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
332 |
tweets = [], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
333 |
lastpos = 0, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
334 |
arcs = [], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
335 |
tweet_ids = [], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
336 |
date_struct = [], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
337 |
date_levels = [ |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
338 |
3600 * 1000, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
339 |
15 * 60 * 1000, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
340 |
5 * 60 * 1000, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
341 |
60 * 1000, |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
342 |
15 * 1000 |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
343 |
], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
344 |
keys_to_delete = [ |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
345 |
'in_reply_to_screen_name', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
346 |
'in_reply_to_user_id', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
347 |
'retweeted', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
348 |
'place', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
349 |
'geo', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
350 |
'source', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
351 |
'contributors', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
352 |
'coordinates', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
353 |
'retweet_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
354 |
'favorited', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
355 |
'truncated', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
356 |
'possibly_sensitive' |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
357 |
], |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
358 |
user_keys_to_delete = [ |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
359 |
'default_profile_image', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
360 |
'show_all_inline_media', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
361 |
'contributors_enabled', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
362 |
'profile_sidebar_fill_color', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
363 |
'created_at', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
364 |
'lang', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
365 |
'time_zone', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
366 |
'profile_sidebar_border_color', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
367 |
'follow_request_sent', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
368 |
'profile_background_image_url', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
369 |
'profile_background_image_url_https', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
370 |
'followers_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
371 |
'description', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
372 |
'url', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
373 |
'geo_enabled', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
374 |
'profile_use_background_image', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
375 |
'default_profile', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
376 |
'following', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
377 |
'profile_text_color', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
378 |
'is_translator', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
379 |
'favourites_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
380 |
'listed_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
381 |
'friends_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
382 |
'profile_link_color', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
383 |
'protected', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
384 |
'location', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
385 |
'notifications', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
386 |
'profile_image_url_https', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
387 |
'statuses_count', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
388 |
'verified', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
389 |
'profile_background_color', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
390 |
'profile_background_tile', |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
391 |
'utc_offset' |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
392 |
], |
|
332
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
393 |
app = http.createServer(httpHandler), |
|
738594562e44
Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
331
diff
changeset
|
394 |
io = socketio.listen(app), |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
395 |
db = new sqlite.Database(); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
396 |
|
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
397 |
/* MAIN CODE */ |
|
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
398 |
|
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
399 |
app.listen(app_port); |
|
338
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
400 |
myLog("Listening on port: "+app_port); |
|
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
401 |
myLog("Opening SQLITE file: "+sqlfile); |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
402 |
db.open(sqlfile , function(err) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
403 |
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
|
404 |
createTables(); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
405 |
}); |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
406 |
|
|
325
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
407 |
if (RECORD_NEW_TWEETS) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
408 |
requestTwitter(); |
|
325
7d9c576bfaac
Some changes - added multi-zoom level on client
Raphael Velt <raph.velt@gmail.com>
parents:
314
diff
changeset
|
409 |
} |
| 314 | 410 |
|
411 |
io.set('log level', 0); |
|
412 |
io.sockets.on('connection', function(socket) { |
|
|
338
60dff8a71024
Added alternate configuration
Raphael Velt <raph.velt@gmail.com>
parents:
335
diff
changeset
|
413 |
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
|
414 |
try { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
415 |
socket.emit('tweetSummary', { tweetcount : lastpos }); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
416 |
} catch (err) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
417 |
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
|
418 |
} |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
419 |
socket.on('updateTweets', function(data) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
420 |
if (data.tweets.length) { |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
421 |
getSendTweets(data.tweets, socket); |
|
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
422 |
} |
|
326
c28048fb63b4
Added visual timeline feature to node client
Raphael Velt <raph.velt@gmail.com>
parents:
325
diff
changeset
|
423 |
}); |
|
331
03c69425efa6
Added SQLite Database in Node Server
Raphael Velt <raph.velt@gmail.com>
parents:
326
diff
changeset
|
424 |
socket.on('updateTimeline', function(data) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
425 |
getSendTimeline(data, socket); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
426 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
427 |
socket.on('tweetPosByDate', function(data) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
428 |
getSendTweetPosByDate(data.date, socket); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
429 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
430 |
socket.on('linkedTweets', function(data) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
338
diff
changeset
|
431 |
getSendLinkedTweets(data.tweetpos, socket); |
| 314 | 432 |
}); |
433 |
}); |