npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

decolar-flights-scraper

v0.0.6

Published

scrape flight data from decolar.com and despegar.com

Downloads

5

Readme

decolar-flights-scraper

A simple Node.JS module to scrape flights data from Decolar.com/Desapegar.com.

Installation

npm install decolar-flights-scraper

Usage

Available methods:

  • search: Retrives a list of flights for the given params.
  • getAirportCode: Retrives codes of airports and cities to be used in search method.

search

Retrieves a list of flights.

Required params :

  • type: Indicates if the flight is one-way or roundtrip. Possible values: roundtrip and one-way.
  • departureLocation: The three letter city or airport code. You can use the getAirportCode to find out.
  • arriveLocation: The same three letter city or airpot code, as used in de departureLocation param.
  • departureDate: The date you plan to leave the departure location. Should be in format: YYYY-MM-DD.
  • arriveDate: The date you plan to arrive in the departure location. Should be in format: YYYY-MM-DD. (This params is required unless the type is one-way).

Optional Params:

  • adultNumber: (defaults to 1). Sets the number of adults. Must be an integer.
  • fullDetail: (defaults to false). By default, only the most crucial fields will be returned. Pass it as true to get the complete documents. It can be a bit verbose.

Example:

const decolar = require('decolar-flights-scraper');

const opts = {
    type: 'roundtrip',
    departureLocation: 'sao',
    arriveLocation: 'nyc',
    departureDate: '2017-09-26',
    arriveDate: '2017-10-10'
};

decolar.search(opts)
    .then(console.log)
    .catch(console.log)

Results:

[ { totalPrice: 2735,
    currencyPriceCode: 'BRL',
    airlines: [ 'Copa Airlines' ] },
  { totalPrice: 2735,
    currencyPriceCode: 'BRL',
    airlines: [ 'Copa Airlines' ] },
  { totalPrice: 2752,
    currencyPriceCode: 'BRL',
    airlines: [ 'Avianca' ] },
  { totalPrice: 2920,
    currencyPriceCode: 'BRL',
    airlines: [ 'Avianca' ] },
    (...)
]

getAirportCode

Retrieves information about a city or airport searched. The result contain the three letter code to be used in the search method. Use it if you don't know the codes for your flight.

Options:

  • query: The partial or complete name of the city or airport which you want more information. It must contain at least 3 characters.
  • locale: (optional, by default is en_US). Set results language.

Examples:

const decolar = require('decolar-flights-scraper');

decolar.getAirportCode({ query: 'frankfurt '})
    .then(console.log);

Results:

{
  "unified": false,
  "data": {
    "AIRPORT": [
      {
        "object_id": "2313",
        "facet": "city",
        "description": "Frankfurt, Germany",
        "type": "CITY",
        "code": "FRA",
        "childs": [
          {
            "object_id": "193866",
            "facet": "airport",
            "description": "Frankfurt International  (rhein-main) Airport, Frankfurt, Germany",
            "type": "AIRPORT",
            "code": "FRA",
            "fuzzy_search_result": false,
            "latitude": 50.05072,
            "longitude": 8.56411
          },
          {
            "object_id": "193867",
            "facet": "airport",
            "description": "Neu Isenburg Airport, Frankfurt, Germany",
            "type": "AIRPORT",
            "code": "QGV",
            "fuzzy_search_result": false,
            "latitude": 50.05,
            "longitude": 8.683333
          },
          {
            "object_id": "193868",
            "facet": "airport",
            "description": "Frankfurt-Hahn Airport, Frankfurt, Germany",
            "type": "AIRPORT",
            "code": "HHN",
            "fuzzy_search_result": false,
            "latitude": 49.946815,
            "longitude": 7.27078
          }
        ]
      }
    ],
    "CITY": [
      {
        "object_id": "2313",
        "facet": "city",
        "description": "Frankfurt, Hessen, Germany",
        "type": "CITY",
        "code": "FRA",
        "fuzzy_search_result": false,
        "latitude": 50.11337,
        "longitude": 8.681362,
        "parent": {
          "object_id": "30453",
          "facet": "administrative_division",
          "type": "ADMINISTRATIVE_DIVISION"
        }
      }
    ]
  }
}

Use the code data.AIRPORT[0].code or data.CITY[0].code in the search method for example.

More Info

  • This module hits directly the decolar.com/despegar.com APIs, thus be careful of the requests amount you send at once, because even having set properly headers to avoid being detected as a crawler, with a careless and exaggerated usage of this module can face a ** blocked ip ** problem for a short period of time. We suggest you to throttle the requests or even distribute them among different servers if you have enough hardware resources.

  • As the decolar.com/despegar.com API takes some seconds to respond ( you can note this behavior in their websites ), this module will take this seconds to retrieve the flights list as well.

Contributing

This module is quite recent, hence it has a tone of "TODOs" (some are explicit in the code) and things to be improved. If you have some suggestions or have found a bug, we will really appreciate if you open an issue or send a PR.