-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.js
54 lines (50 loc) · 1.14 KB
/
backup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var wolfram = require('wolfram-alpha').createClient("4GJ2YK-Q4QLHV8XPV");
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
wolfram.query(msg, function (err, result) {
k = 0;
if (err) throw err;
x = JSON.stringify(result, null, 2);
io.emit('chat message', msg);
for (var i = 0; i<x.length; i++){
if(x[i]=='t'){
i++;
if(!(x[i]=='i'||x[i]=='e'))
continue;
y="t"+x[i];
i++;
if(!(x[i]=='t'||x[i]=='x'))
continue;
while(x[i]!='\n'){
if(x[i]!='"'&&x[i]!=',')
y+=x[i];
else if(x[i]=='"')
y+=' ';
i++;
k++;
}
console.log(y);
if(k == 1)
msg = msg + y;
else
msg = y;
io.emit('chat message', msg );
}
}
});
console.log('message: ' + msg);
});
socket.on('chat message1', function(msg){
io.emit('chat message1', msg );
console.log('message: ' + msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});