cia-world-leaders
Version:
Serves as an independent data scraping module, complete with ontology and full scraping ability for the CIA World Leaders site
39 lines (38 loc) • 2.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var cheerio = require("cheerio");
var rp = require("request-promise");
var funktologies_1 = require("funktologies");
var constants_1 = require("../constants/constants");
var globalStore_1 = require("../constants/globalStore");
var country_code_lookup_tables_1 = require("./country-code-lookup-tables");
var country_to_id_1 = require("./country-to-id");
function getCountries() {
return rp('https://www.cia.gov/library/publications/the-world-factbook/')
.then(function (html) {
var _a;
var $ = cheerio.load(html);
var cNames = $('#search-place option').toArray()
.map(function (c) {
var dCode = $(c).prev().attr('data-place-code');
return {
dataCode: dCode,
isoCode: country_code_lookup_tables_1.dataCodeToIsoCode(dCode),
name: $(c).prev().text().replace(/\\n/g, ' ').trim()
};
})
.filter(function (country) { return !!country.name && !constants_1.consts.BASE.COUNTRY_BLACKLIST.includes(country.name.toLowerCase()); });
(_a = globalStore_1.store.countriesInList).push.apply(_a, cNames);
globalStore_1.store.countriesInList.forEach(function (country) {
var id = country_to_id_1.countryToId(country.dataCode);
globalStore_1.store.countries[id] = funktologies_1.entityMaker(constants_1.consts.ONTOLOGY.HAS_COUNTRY, constants_1.consts.ONTOLOGY.ONT_COUNTRY, id, country.name)[constants_1.consts.ONTOLOGY.HAS_COUNTRY];
globalStore_1.store.countries[id].datatypeProperties[constants_1.consts.ONTOLOGY.DT_GEC_CODE] = country.dataCode;
globalStore_1.store.countries[id].datatypeProperties[constants_1.consts.ONTOLOGY.DT_ISO_CODE] = country.isoCode;
});
})
.catch(function (err) {
globalStore_1.store.errorLogger(new Date().toISOString() + '\n\n' + err.toString() + '\n\n');
});
}
exports.getCountries = getCountries;
;
;