diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6970e39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +logs +*.log +.DS_Store +node_modules diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d49ef84 --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +screenshot.jpg diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a5a1bed --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +Copyright (c) 2016, Nate Goldman + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2316adc --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# himawari-bg + +> Set the latest image from Himawari 8 as your desktop background + +[![npm][npm-image]][npm-url] +[![travis][travis-image]][travis-url] +[![standard][standard-image]][standard-url] + +[npm-image]: https://img.shields.io/npm/v/himawari-bg.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/himawari-bg +[travis-image]: https://img.shields.io/travis/ngoldman/himawari-bg.svg?style=flat-square +[travis-url]: https://travis-ci.org/ngoldman/himawari-bg +[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square +[standard-url]: http://npm.im/standard + +![](screenshot.jpg) + +Note: This is alpha quality! Tested only on OSX. + +## Install + +``` +npm i -g himawari-bg +``` + +## Usage + +```js +var bg = require('himawari-bg') + +bg({ + /** + * The location to save the resulting image. + * Default: `~/Pictures/himawari-images/${Date.now()}.jpg` + * @type {String} + */ + outfile: '/path/to/output/earth.jpg', + + /** + * The time of the picture desired. If you want to get the latest image, use 'latest'. + * Default: 'latest' + * @type {String|Date} + */ + date: 'latest', // Or new Date() or a date string + + /** + * The zoom level of the image. Can be 1-5 (default: 1) + * Each zoom level requires more images to be downloaded and therefore stitched + * together. Higher zoom yields a higher resolution image. + * Default: 2 + * @type {Number} + */ + zoom: 2, + + /** + * If set to true, an image on the infrared light spectrum will be generated + * Default: false + * @type {Boolean} + */ + infrared: false +}) +``` + +### Command Line Interface + +``` +Usage: himawari-bg [options] + --outfile, -o The location to save the resulting image. (default: `~/Pictures/himawari-images/${Date.now()}.jpg`) + --zoom, -z The zoom level of the image. Can be 1-5. (default: 2) + --date, -d The time of the picture desired. If you want to get the latest image, use "latest". (default: "latest") + --infrared, -i Capture picture on the infrared spectrum. (default: false) + --help, -h Show help. +``` + +### Acknowledgement + +Thanks to [celoyd](https://github.com/celoyd) for the inspiring [glittering.blue](https://glittering.blue/) and [jakiewtf](https://github.com/jakiestfu) for creating [himawari.js](https://github.com/jakiestfu/himawari.js). + +## License + +[ISC](LICENSE) diff --git a/cli.js b/cli.js new file mode 100755 index 0000000..e22b2f7 --- /dev/null +++ b/cli.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +var bg = require('./') +var cliclopts = require('cliclopts') +var minimist = require('minimist') + +var allowedOptions = [ + { + name: 'outfile', + abbr: 'o', + help: 'Location to save image. (default: `~/Pictures/himawari-images/${Date.now()}.jpg`)' + }, + { + name: 'zoom', + abbr: 'z', + help: 'The zoom level of the image. Can be 1-5.', + default: 2 + }, + { + name: 'date', + abbr: 'd', + help: 'Time of the picture desired. Can also be "latest".', + default: 'latest' + }, + { + name: 'infrared', + abbr: 'i', + help: 'Capture picture on the infrared spectrum.', + boolean: true, + default: false + }, + { + name: 'help', + abbr: 'h', + help: 'Show help.', + boolean: true + } +] + +var opts = cliclopts(allowedOptions) +var argv = minimist(process.argv.slice(2), opts.options()) + +if (argv.help) { + console.log('Usage: himawari-bg [options]') + opts.print() + process.exit() +} + +bg(argv) diff --git a/index.js b/index.js new file mode 100644 index 0000000..00f993f --- /dev/null +++ b/index.js @@ -0,0 +1,43 @@ +var himawari = require('himawari') +var path = require('path') +var wallpaper = require('wallpaper') +var mkdirp = require('mkdirp') +var ProgressBar = require('progress') +var untildify = require('untildify') +var bar = null + +module.exports = function (opts) { + var outfile = untildify(opts.outfile || `~/Pictures/himawari-images/${Date.now()}.jpg`) + + // create outfile directory just in case + mkdirp.sync(path.dirname(outfile)) + + himawari({ + zoom: opts.zoom || 2, + outfile: outfile, + date: opts.date || 'latest', + infrared: opts.infrared || false, + chunk: function (info) { + bar = bar || createProgressBar(info.total) + bar.tick() + }, + error: function (err) { + console.log(err) + process.exit(1) + }, + success: function () { + console.log(`Setting ${outfile} as background...`) + wallpaper.set(outfile) + console.log('Complete!') + } + }) +} + +function createProgressBar (total) { + return new ProgressBar('Downloading satellite images [:bar] :percent :etas', { + complete: '=', + incomplete: ' ', + width: 20, + total: total + }) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6ba41b2 --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "himawari-bg", + "description": "Set the latest image from Himawari 8 as your desktop background", + "version": "1.0.0-alpha", + "author": "Nate Goldman ", + "bugs": { + "url": "https://github.com/ngoldman/himawari-bg/issues" + }, + "dependencies": { + "cliclopts": "^1.1.1", + "himawari": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "progress": "^1.1.8", + "untildify": "^2.1.0", + "wallpaper": "^2.1.0" + }, + "devDependencies": { + "standard": "^6.0.4" + }, + "bin": { + "himawari-bg": "./cli.js" + }, + "homepage": "https://github.com/ngoldman/himawari-bg", + "keywords": [ + "background", + "desktop", + "earth", + "himawari", + "himawari-8", + "satellite", + "wallpaper" + ], + "license": "ISC", + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/ngoldman/himawari-bg.git" + }, + "scripts": { + "start": "node index.js", + "test": "standard" + } +} diff --git a/screenshot.jpg b/screenshot.jpg new file mode 100644 index 0000000..7e2fafb Binary files /dev/null and b/screenshot.jpg differ