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

Rewrite downloader #154

Merged
merged 2 commits into from
Dec 13, 2016
Merged
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
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"esversion": 6,
"node": true,
"curly": true,
"eqeqeq": true,
Expand Down
40 changes: 21 additions & 19 deletions lib/tasks/download.js
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;
});
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
"pelias-logger": "0.1.0",
"pelias-model": "4.4.0",
"pelias-wof-admin-lookup": "2.8.0",
"progress": "^1.1.5",
"progress-stream": "^1.2.0",
"request": "^2.34.0",
"through2": "^2.0.1",
"through2-filter": "^2.0.0"
Expand Down