-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge pull request #154 from pelias/rewrite-downloader
Rewrite downloader
- Loading branch information
Showing
3 changed files
with
22 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"esversion": 6, | ||
"node": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs-extra'), | ||
util = require('util'), | ||
request = require('request'), | ||
_ = require('lodash'), | ||
progress = require('../../util/streamProgressBar'), | ||
logger = require( 'pelias-logger' ).get( 'geonames' ); | ||
const child_process = require('child_process'); | ||
const logger = require( 'pelias-logger' ).get( 'geonames' ); | ||
|
||
// use datapath setting from your config file | ||
var settings = require('pelias-config').generate(); | ||
var basepath = settings.imports.geonames.datapath; | ||
const settings = require('pelias-config').generate(); | ||
const basepath = settings.imports.geonames.datapath; | ||
|
||
module.exports = function (filename) { | ||
const remoteFilePath = `http://download.geonames.org/export/dump/${filename}.zip`; | ||
const localFileName = `${basepath}/${filename}.zip`; | ||
|
||
var remoteFilePath = util.format( 'http://download.geonames.org/export/dump/%s.zip', filename ); | ||
var localFileName = util.format( '%s/%s.zip', basepath, filename ); | ||
logger.info( 'downloading datafile from:', remoteFilePath ); | ||
|
||
fs.mkdirs('data', function(error) { | ||
if( error ){ | ||
logger.error( error ); | ||
return; | ||
} | ||
logger.info( 'downloading datafile from:', remoteFilePath ); | ||
const command = `curl ${remoteFilePath} > ${localFileName}`; | ||
|
||
request.get( remoteFilePath ) | ||
.pipe( progress( _.padEnd( localFileName, 30 ) ) ) | ||
.pipe( fs.createWriteStream( localFileName ) ); | ||
const job = child_process.exec(command); | ||
|
||
job.stdout.on('data', (data) => { | ||
process.stdout.write(data); | ||
}); | ||
|
||
job.stderr.on('data', (data) => { | ||
process.stderr.write(data); | ||
}); | ||
|
||
job.on('close', (code) => { | ||
console.log(`Geonames download finished with exit code ${code}`); | ||
process.exitCode = code; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters