Skip to content

Commit

Permalink
feat(sqlite): download sqlite all default endpoint to geocode.earth
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit committed Mar 9, 2020
1 parent 05261e3 commit 3a86846
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const Joi = require('@hapi/joi');
module.exports = Joi.object().keys({
imports: Joi.object().required().keys({
whosonfirst: Joi.object().required().keys({
countries: Joi.alternatives().try(
Joi.string(),
Joi.array().items(Joi.string()).default([])
).default([]),
dataHost: Joi.string(),
datapath: Joi.string().required(),
importPlace: [
Expand Down
17 changes: 15 additions & 2 deletions utils/download_sqlite_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const commandExistsSync = require('command-exists').sync;

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

const wofDataHost = config.get('imports.whosonfirst.dataHost') || 'https://dist.whosonfirst.org';
const wofDataHost = config.get('imports.whosonfirst.dataHost') || 'https://data.geocode.earth/wof/dist';
const COMBINED_REGEX = /^whosonfirst-data-(admin|postalcode|venue)-latest/;

function download(callback) {
//ensure required directory structure exists
Expand All @@ -21,12 +22,24 @@ function download(callback) {
const maxSimultaneousDownloads = config.get('imports.whosonfirst.maxDownloads') || 4;
const cpuCount = os.cpus().length;
const simultaneousDownloads = Math.max(maxSimultaneousDownloads, Math.min(1, cpuCount / 2));
const countryFilter = () => {
const countries = Array.isArray(config.imports.whosonfirst.countries) ?
config.imports.whosonfirst.countries : [config.imports.whosonfirst.countries];
return (e) => {
if (countries.length === 0) {
return COMBINED_REGEX.test(e.name_compressed);
}
return countries.some(c => e.name_compressed.indexOf(`-${c}-latest`) >= 0);
};
};

const generateSQLites = () => {
const files = {};
const content = JSON.parse(downloadFileSync(`${wofDataHost}/sqlite/inventory.json`))
// Only latest compressed files
.filter(e => e.name_compressed.indexOf('latest') >= 0)
// Only wanted countries
.filter(countryFilter())
// Postalcodes only when importPostalcodes is ture and without --admin-only arg
.filter(e => e.name_compressed.indexOf('postalcode') < 0 ||
(config.imports.whosonfirst.importPostalcodes && process.argv[2] !== '--admin-only'))
Expand Down Expand Up @@ -55,7 +68,7 @@ function download(callback) {
if (commandExistsSync('lbzip2')) {
extract = 'lbzip2';
} else {
extract = 'bunzip';
extract = 'bunzip2';
}
} else if (/\.db\.tar\.bz2$/.test(sqlite.name_compressed)) {
// Check if we have lbzip2 installed
Expand Down

0 comments on commit 3a86846

Please sign in to comment.