Skip to content

Commit

Permalink
Urls flag and version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jakiestfu committed Feb 18, 2016
1 parent 2281c08 commit 32f5ddb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -89,6 +89,12 @@ himawari({
*/
timeout: 30000,

/**
* If true, only prints the URLs of the images that would have been downloaded
* @type {Boolean}
*/
urls: false,

/**
* A success callback if the image downloads successfully
* @type {Function}
Expand Down Expand Up @@ -132,7 +138,9 @@ Usage: himawari [options]
--parallel, -p Parallelize downloads for increased speeds (can be CPU intensive)
--skipempty, -s Skip saving images that contain no useful information (i.e. "No Image") (Default: `true`)
--timeout, -t The max duration in milliseconds before requests for images and data times out (Default: `30000`)
--urls, -u Only print the URLs of the images that would have been downloaded (Default: `false`)
--infrared, -i Capture picture on the infrared spectrum (Default: `false`)
--version, -v Prints the version of the package
--help, -h Show help
```

Expand Down
31 changes: 26 additions & 5 deletions bin/cli.js
Expand Up @@ -6,6 +6,7 @@ var himawari = require('../');
var minimist = require('minimist');
var moment = require('moment');
var path = require('path');
var pkg = require('../package.json');

var allowedOptions = [
{
Expand Down Expand Up @@ -48,12 +49,24 @@ var allowedOptions = [
abbr: 't',
help: 'The max duration in milliseconds before requests for images and data times out'
},
{
name: 'urls',
abbr: 'u',
help: 'Only print the URLs of the images that would have been downloaded',
boolean: true
},
{
name: 'infrared',
abbr: 'i',
help: 'Capture picture on the infrared spectrum',
boolean: true
},
{
name: 'version',
abbr: 'v',
help: 'Prints the version of the package',
boolean: true
},
{
name: 'help',
abbr: 'h',
Expand All @@ -68,7 +81,12 @@ var argv = minimist(process.argv.slice(2), opts.options());
if (argv.help) {
console.log('Usage: himawari [options]');
opts.print();
process.exit();
return process.exit();
}

if (argv.version) {
console.log(pkg.version);
return process.exit();
}

var parsedDate = new Date(argv.date || new Date().toString());
Expand All @@ -95,8 +113,6 @@ if (argv.outfile) {
outfile = path.join(dirname, defaultBasename);
}

console.log('Creating ' + basename + ' in ' + dirname + ' ...');

himawari({
zoom: argv.zoom,
outfile: outfile,
Expand All @@ -106,15 +122,20 @@ himawari({
parallel: argv.parallel,
skipEmpty: argv.skipempty,
timeout: argv.timeout,
urls: argv.urls,
success: function (info) {
console.log('Complete', info);
if (!argv.urls) {
console.log('Complete', info);
}
process.exit();
},
error: function (err) {
console.log(err);
process.exit(1);
},
chunk: function (info) {
console.log('Saved', info.part + '/' + info.total);
if (!argv.urls) {
console.log('Saved', info.part + '/' + info.total);
}
}
});
22 changes: 11 additions & 11 deletions index.js
Expand Up @@ -27,6 +27,7 @@ var himawari = function (userOptions) {
parallel: false,
skipEmpty: true,
timeout: 30000, // 30 seconds
urls: false,
zoom: 1,

success: function () {},
Expand Down Expand Up @@ -151,6 +152,12 @@ var himawari = function (userOptions) {

// Pipe image
log('Requesting image...', uri);

if (options.urls) {
console.log(uri);
return inner_cb();
}

request({
method: 'GET',
uri: uri,
Expand Down Expand Up @@ -181,6 +188,10 @@ var himawari = function (userOptions) {
return options.error(err);
}

if (options.urls) {
return options.success();
}

// If we are skipping this image
if (skipImage) {
// Clean
Expand All @@ -191,17 +202,6 @@ var himawari = function (userOptions) {
return options.success('No image available');
}

// if (tiles.length === 1) {
// log('Skipping stiching...');
//
// var tile = tiles[0];
// fs.renameSync(path.join(tmp.name, tile.name), outfile);
// log('Cleaning temp files...');
//
// tmp.removeCallback();
// return options.success('File saved to ' + outfile);
// }

// New Graphics Magick handle
var magick = gm();

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "himawari",
"version": "1.3.0",
"version": "1.3.2",
"description": "Download real-time images of Earth from the Himawari-8 satellite",
"main": "index.js",
"repository": "https://github.com/jakiestfu/himawari.js.git",
Expand Down

0 comments on commit 32f5ddb

Please sign in to comment.