--- a/common/corpus-common-addon/lib/commands/dl-fixtures.js Mon May 30 11:27:18 2016 +0200
+++ b/common/corpus-common-addon/lib/commands/dl-fixtures.js Mon May 30 12:29:55 2016 +0200
@@ -8,6 +8,7 @@
var request = require('request');
var _ = require('lodash');
var fs = require('fs');
+var chalk = require('chalk');
// taken from http://stackoverflow.com/a/17238793
// `condition` is a function that returns a boolean
@@ -77,7 +78,7 @@
dl_themes: function(commandOptions) {
return this.dl_countmap(commandOptions, 'themes');
},
- dl_documents_ids: function(commandOptions, rawArgs, ids) {
+ dl_documents_ids: function(commandOptions, rawArgs, ids, ui) {
var nextPageUrl = commandOptions.url;
var pageIndex = 1;
@@ -87,6 +88,8 @@
function() { return pageIndex <= commandOptions.page && nextPageUrl; },
function() {
var deferred = Q.defer();
+ ui.writeLine(chalk.yellow('Download Documents : getting page ' + pageIndex));
+
request.get({url: nextPageUrl, json: true}, function (err, res, body) {
if (err) {
return deferred.reject(err);
@@ -112,14 +115,15 @@
}
);
},
- dl_transcripts: function(commandOptions, rawArgs) { // eslint-disable-line no-unused-vars
+ dl_transcripts: function(commandOptions, rawArgs, ui) { // eslint-disable-line no-unused-vars
var ids = [];
- return this.dl_documents_ids(commandOptions, rawArgs, ids).then(function() {
+ return this.dl_documents_ids(commandOptions, rawArgs, ids, ui).then(function() {
return Q.all(_.map(ids, function(id) {
var deferred = Q.defer();
request.get({url: commandOptions.url + encodeURIComponent(encodeURIComponent(id)) + '/transcript', json: true}, function (err, res, body) {
+ ui.writeLine(chalk.green('Download transcripts : getting transcript ' + id));
if (err) {
return deferred.reject(err);
} else if (res.statusCode === 404) {
@@ -147,15 +151,15 @@
}.bind(this));
},
- dl_documents: function(commandOptions, rawArgs) { // eslint-disable-line no-unused-vars
+ dl_documents: function(commandOptions, rawArgs, ui) { // eslint-disable-line no-unused-vars
var ids = [];
- return this.dl_documents_ids(commandOptions, rawArgs, ids).then(function() {
- console.log(ids);
+ return this.dl_documents_ids(commandOptions, rawArgs, ids, ui).then(function() {
return Q.all(_.map(ids, function(id) {
var deferred = Q.defer();
request.get({url: commandOptions.url + encodeURIComponent(encodeURIComponent(id)), json: true}, function (err, res, body) {
+ ui.writeLine(chalk.green('Download transcripts : getting doc ' + id));
if (err) {
return deferred.reject(err);
} else if (res.statusCode !== 200) {
@@ -186,6 +190,6 @@
this.format = commandOptions.format || 'es6';
- return this['dl_' + type](commandOptions, rawArgs);
+ return this['dl_' + type](commandOptions, rawArgs, this.ui);
}
});