Skip to content

Commit

Permalink
Fix capitalization handling in country download
Browse files Browse the repository at this point in the history
This is a small PR into #487
that allows country codes to be specified in upper case or lower case.

Before this, specifying country codes in anything but lowercase would
cause the downloader to skip all files.
  • Loading branch information
orangejulius committed Apr 23, 2020
1 parent ec626b4 commit fea6c5d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions utils/download_sqlite_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ function on_done() {
console.log('All done!');
}

function getCountriesToDownload() {
const countries = Array.isArray(config.imports.whosonfirst.countryCode) ?
config.imports.whosonfirst.countryCode : [config.imports.whosonfirst.countryCode];

return countries.map((c) => { return c.toLowerCase(); });
}

function download(callback) {
//ensure required directory structure exists
fs.ensureDirSync(path.join(config.imports.whosonfirst.datapath, 'sqlite'));
Expand All @@ -29,8 +36,7 @@ function download(callback) {
const cpuCount = os.cpus().length;
const simultaneousDownloads = Math.max(maxSimultaneousDownloads, Math.min(1, cpuCount / 2));
const countryFilter = () => {
const countries = Array.isArray(config.imports.whosonfirst.countryCode) ?
config.imports.whosonfirst.countryCode : [config.imports.whosonfirst.countryCode];
const countries = getCountriesToDownload();
return (e) => {
if (countries.length === 0) {
// This is specific to geocode earth, it will select global sqlites
Expand Down Expand Up @@ -108,4 +114,4 @@ function download(callback) {
async.parallelLimit(downloadFunctions, simultaneousDownloads, callback);
}

download(on_done);
download(on_done);

0 comments on commit fea6c5d

Please sign in to comment.