File size: 2,085 Bytes
5893f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
var skyscanner = require('./skyscanner');
var util = require('util');
var promise = require('bluebird');
var request = require('request-promise');
var _ = require('lodash');

// This API key is shared in API documentation, you should register your own
skyscanner.setApiKey('fl989112564576873089361895446787');

skyscanner.getLocation('Istanbul').then(function (data) {
    console.log(data);
});

skyscanner.searchCache('ADA-sky','BERL-sky', '2017-04-24', '2017-04-24').then(function (data){
    //data is the response of skyscanner
    //console.log is a function that prints the terminal.
    //console.log(data);
    //priceAndDate is the splitted version of data.
    console.log(JSON.stringify(data));
    var detailInformation = data.Quotes.map(function (quote) {

        var segments = [quote.OutboundLeg, quote.InboundLeg].map(function (segment, index) {

            var departPlace = _.filter(data.Places, { PlaceId: segment.OriginId })[0];
            var arrivePlace = _.filter(data.Places, { PlaceId: segment.DestinationId })[0];
            var carriers = segment.CarrierIds.map(c => _.filter(data.Carriers, { CarrierId: c })[0].Name);

            return {
                group: index + 1,
                departAirport: { code: departPlace.IataCode, name: departPlace.Name },
                arriveAirport: { code: arrivePlace.IataCode, name: arrivePlace.Name },
                departCity: { code: departPlace.CityId, name: departPlace.CityName },
                arriveCity: { code: arrivePlace.CityId, name: arrivePlace.CityName },
                departTime: segment.DepartureDate,
                carriers: carriers
            };
        });
        console.log(segments);
        return {
            //segments: segments,
            price: quote.MinPrice,
            direct: quote.Direct,
        }
    });
    console.log(detailInformation);
});
//This is example and it is suspended.
/*skyscanner.searchLive('IST-sky','ESB-sky', '2017-06-20', '2017-06-30', 1, 0, 0, true).then(function (data) {
    console.log(util.inspect(data[0], false, 99999));
});*/