-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (60 loc) · 2.58 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
exports.getFlightsInfo = function(action, callback) {
var http = require('http');
var cheerio = require('cheerio');
const host = 'www.prg.aero';
const pathArival = '/en/flight-info/arrivals-departures/arrivals/?hour=all&destination=0&carrier=0&act=main->param->param->param->setFiltr';
const pathDepartures = '/en/flight-info/arrivals-departures/departures/?hour=all&destination=0&carrier=0&act=main->param->param->param->setFiltr';
if(action === 'arrivals'){
objLink = pathArival;
}
if(action === 'departures'){
objLink = pathDepartures;
}
var options = {
host: 'www.prg.aero',
path: objLink
}
var request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
$ = cheerio.load(data);
const finalObjects = [];
// traversing all rows
if(action === 'arrivals'){
$('.letistepraha_cms_ui_content_departurearrival_arrival > tbody > tr').each(function(i, elem) {
const arrivalObj = {dateTime: $(elem.children[1]).text(),
flightId: $(elem.children[3].children[0].children[1]).text(),
flightNum: $(elem.children[3].children[0].children[0]).text(),
Target: $(elem.children[5]).text(),
Company: $(elem.children[7]).text(),
Terminal: $(elem.children[9]).text(),
Status: $(elem.children[11]).text(),
};
finalObjects.push(arrivalObj);
});
}
if(action === 'departures'){
$('.letistepraha_cms_ui_content_departurearrival_departure > tbody > tr').each(function(i, elem) {
const arrivalObj = {dateTime: $(elem.children[1]).text(),
flightId: $(elem.children[3].children[0].children[1]).text(),
flightNum: $(elem.children[3].children[0].children[0]).text(),
Target: $(elem.children[5]).text(),
Company: $(elem.children[7]).text(),
Terminal: $(elem.children[9]).text(),
CheckIn: $(elem.children[11]).text(),
Status: $(elem.children[13]).text(),
};
finalObjects.push(arrivalObj);
});
}
callback(finalObjects);
});
});
request.on('error', function (e) {
console.log(e.message);
});
request.end();
}