1.1.3 • Published 5 years ago
@project-medusa/collector-utils v1.1.3
medusa-collector-utils
medusa-collector-utils is a utility package used by MedusaCollector
Installation
npm i @project-medusa/collector-utilsUsage
For a better understanding of how this package is used, please take a look at the MedusaCollector package mentioned above.
API
Table Of Contents
AirportCollector
- Description: The
AirportCollectorclass's purpose is to find out which airports are covered by a specific eAIP. It also caches the results undercache/XX_airports.json - Type:
class - Constructor Parameters:
aoi:- Type:
string - Description: 2-letter area code (EG, EY, EV, ...)
- Type:
aerodromeParseFunction- Type:
function - Description: This function is called to parse out an eAIP aerodrome line. Examples:
AD-2.EYPAdetails ->aerodromeParseFunction-> EYPA
- Type:
- Relevant Methods:
findCoveredAirports:- Async: true
- Returns:
array[string] - Description: This method either looks in cache or grabs and parses the covered airfields by an eAIP.
- Usage:
const { AirportCollector } = require('@project-medusa/collector-utils')
const airportCollector = new AirportCollector(process.env.AOI, parseAerodromeString);- Also see MedusaCollector
Collector
- Description: The Collector parses the
htmldocument and calls specific Parser methods to further extract the information from the parsedhtml - Type:
class - Constructor Parameters:
parser:- Type: instance of Parser
- Relevant Methods:
retriveAndParseTable- Async: true
- Returns:
void - Description: This method calls the specific country parsers to parse out an
HTML Tablerow.
Usage:
const { Collector } = require('@project-medusa/collector-utils'); const collector = new Collector(...);Also see Parser
- Also see MedusaCollector
Parser
Description: The
Parserclass is where most of the bussiness logic happens. It's where the runway/intersection information is parsed. Each country, AKA AOI (area of interest), has their own unique parser as each country's information structure is different.Type:
class- Constructor Parameters:
airport- Type:
string - Description: 4-letter airport ICAO code
- Type:
link- Type:
string
- Type:
- Relevant Methods:
runwayRows- Throws: an Error if not overriden by inherited classes
- Description: This method is called for each
HTML Tablerow that contains runway/intersection data. - Returns:
void - Parameters:
rows:- Type:
NodeList {}
- Type:
save- Async: true
- Description: Saves runway results from
this.resultsintoresults/XXXX.json
- Usage:
Note: each inherited class MUST override a method called runwayRows, otherwise an error will be thrown
const { Parser } = require('@project-medusa/collector-utils');
class EY extends Parser {...}- Also see MedusaCollector
Page
- Description: meant for creating and retrieving a puppeteer page
- Type:
object - Relevant methods:
createPage- Parameters:
params- Type:
object - Description: This params object is passed down to a puppeteer function called
puppeteer.launch();
- Type:
- Parameters:
getPage- Description: returns the created puppeteer page.
- Usage:
const { createPage, getPage: page } = require('@project-medusa/collector-utils').Page;
(async () => {
await createPage({ headless: false, slowMo: 0, args: ['--user-agent=New User Agent'] });
await page().goto(currentSource.menuLink);
})();- Also see MedusaCollector