-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·62 lines (53 loc) · 1.99 KB
/
app.js
File metadata and controls
executable file
·62 lines (53 loc) · 1.99 KB
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
55
56
57
58
59
60
61
var mubsub = require('mubsub');
var datejs = require('datejs');
var client = mubsub('mongodb://swalo:84kAanan@ds051658.mongolab.com:51658/swalo');
var channel = client.channel('searches');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'aragorn.mrorange.local',
user : 'sa',
password : 'homermad!'
});
function GetSearchQuery() {
var CreateDate = new Date().add({ seconds: -40}).toString('yyyy-MM-dd HH:mm:ss');
var CreateDate2 = new Date().add({ seconds: -30}).toString('yyyy-MM-dd HH:mm:ss');
console.log(CreateDate);
/*out_BestTotalPrice > 300.0 and*/
var sqlQuery = "SELECT in_FromCity, in_ToCity, in_DepartureDate, in_ReturnDate, Created FROM tomtom.statisticsairsearchlog where in_OneWay = 0 and out_BestNumberOfSeg > 3 and SearchName = 'GETAIRFARESMAIN' and Created > '{0}' and Created < '{1}' order by Created"
sqlQuery = sqlQuery.format(CreateDate, CreateDate2);
return sqlQuery;
}
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
function GetSearchData() {
console.log("**************** NEW SEARCH *****************")
var sql = GetSearchQuery();
console.log(sql);
connection.query(sql, function(err, rows, fields) {
if (err) throw err;
console.log('Got' + rows.length + " rows");
channel.publish('NewSearch', {CreateDate : new Date(), Rows : rows});
/*
rows.forEach(function(item) {
//console.log(item);
console.log("Sending SearchData: " + item.in_FromCity + item.in_ToCity + item.in_DepartureDate + item.in_ReturnDate );
channel.publish('NewSearch', item);
})
*/
});
}
connection.connect();
client.on('error', console.error);
channel.on('error', console.error);
GetSearchData();
setInterval(GetSearchData, 10000 );