Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple countryCodes #408

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions bin/downloadData.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';

const config = require('pelias-config').generate();
const validateISOCode = require('../lib/validateISOCode');

const countryCode = validateISOCode(config.imports.geonames.countryCode);

const filename = countryCode === 'ALL' ? 'allCountries' : countryCode;

const task = require('../lib/tasks/download');
task(filename);
'use strict';

const config = require('pelias-config').generate();
const countryCodeArrayCreator = require('../lib/countryCodeArrayCreator');


const countrycode = countryCodeArrayCreator(config.imports.geonames.countryCode);

const task = require('../lib/tasks/download');
for (var i in countrycode) {
//No ISO code validation required, already done in countryCodeArrayCreator
task(countrycode[i]);
}
19 changes: 9 additions & 10 deletions import.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
const config = require('pelias-config').generate();
const _ = require('lodash');
const logger = require('pelias-logger').get('geonames');
const countryCodeArrayCreator = require('./lib/countryCodeArrayCreator');

if (_.has(config, 'imports.geonames.adminLookup')) {
logger.info('imports.geonames.adminLookup has been deprecated, ' +
'enable adminLookup using imports.adminLookup.enabled = true');
'enable adminLookup using imports.adminLookup.enabled = true');
}

const resolvers = require( './lib/tasks/resolvers' );
const countrycode = countryCodeArrayCreator(config.imports.geonames.countryCode);
const resolvers = require('./lib/tasks/resolvers');
const task = require('./lib/tasks/import');
const validateISOCode = require('./lib/validateISOCode');

const isocode = validateISOCode( config.imports.geonames.countryCode );
const filename = isocode === 'ALL' ? 'allCountries' : isocode;
const source = resolvers.selectSource( filename );

task( source );
for (var i in countrycode) {
//No ISO code validation required, already done in countryCodeArrayCreator
const source = resolvers.selectSource(countrycode[i]);
task(source);
}
22 changes: 22 additions & 0 deletions lib/countryCodeArrayCreator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const validateISOCode = require('./validateISOCode');

//Just wraps the string into an array and returns an array if all countryCodes are valid
function countryCodeArrayCreator(countrycode) {
if (typeof countrycode === 'string') {
const isocode = validateISOCode(countrycode);
const filename = isocode === 'ALL' ? 'allCountries' : isocode;
let countrycodeArray = [];
countrycodeArray.push(filename);
return countrycodeArray;
} else if (Array.isArray(countrycode)) {
for (var i in countrycode) {
validateISOCode(countrycode[i]);
}
return countrycode;
} else {
throw new Error('imports.geonames.countryCode must be either a string ' +
'or an array of strings.');
}
}

module.exports = countryCodeArrayCreator;