Git Product home page Git Product logo

node-apod's Introduction

node-apod

Build Status node version
NPM
"Astronomy Picture of the Day" scraper for node, support multi-language
DEMO PAGE: http://ssarcandy.tw/node-apod/demo.html

Install

npm install --save node-apod

Usage

var APOD = require('node-apod');
var apod = new APOD(API_KEY); // You can get API_KEY at https://api.nasa.gov/index.html#apply-for-an-api-key

apod.get({
    LANG: "en_us", // default en_us
    DATE: '2016-06-24' // default today
}, function(err, data) {
    console.log(data);
});

The response data format as follow:

{
    "lang": "en_us",
    "copyright": "Laurie Hatch",
    "date": "2016-06-23",
    "explanation": "A Full Moon sets as the Solstice Sun rises in this June 20 dawn skyscape. Captured from a nearby peak in central California, planet Earth, the scene looks across the summit of Mount Hamilton and Lick Observatory domes on a calendar date that marks an astronomical change of seasons and hemispherical extremes of daylight hours. Earth's shadow stretches toward the Santa Cruz Mountains on the western horizon. Just above the atmospheric grey shadowband is a more colorful anti-twilight arch, a band of reddened, backscattered sunlight also known as the Belt of Venus. The interplay of solstice dates and lunar months does make this solstice and Full Moon a rare match-up. The next June solstice and Full Moon will fall on the same calendar date on June 21, 2062.",
    "hdurl": "http://apod.nasa.gov/apod/image/1606/LH7407_LickObservatorySolsticeDawnMoonset_1440x960.jpg",
    "media_type": "image",
    "service_version": "v1",
    "title": "Solstice Dawn and Full Moonset",
    "url": "http://apod.nasa.gov/apod/image/1606/LH7407_LickObservatorySolsticeDawnMoonset_1024x683.jpg"
}

Supported language:

  • en_us: English(default)
  • zh_tw: Traditional Chinese
  • cs_cz: Czech
  • fr_fr: French
  • ar_sa: Arabic
  • de_de: German
  • ja_jp: Japanese
  • gl_es: Galician
  • tr_tr: Turkish

If LANG is specified(and is valid), response data will get specified LANG's title and explanation.
For example, set LANG as Traditional Chinese:

apod.get({
    LANG: "zh_tw",
    DATE: '2016-06-23'
}, function(err, data) {
    console.log(data);
});

Will Get something like this:

{
    "lang": "zh_tw",
    "copyright": "Laurie Hatch",
    "date": "2016-06-23",
    "explanation": "說明: 在這幅6月20日的黎明天空影像裡,東升的夏至太陽有西沉的滿月為伴。在天文學上標誌南北半球季節更迭和最長和最短白畫的這個日子,攝於地球.加州中部一座山峰的這幅影像,眺望鄰近漢密爾頓山頂和里克天文台的圓頂。影像中,地球的影子綿延向位在西方地平線的聖克魯斯山脈伸展;在灰色的大氣暗影帶之上,可見到名為金星帶的彩反輝弧,一圈由反向散射的陽光所構成的泛紅光帶。交替出現的至日與農曆月份,恰好在這一天帶來了罕見的夏至與滿月的交會。下一次夏至與滿月重逢,則要等到2062年的6月21日。(Mount \r\nHamilton 漢密爾頓山、漢莫頓山)",
    "hdurl": "http://apod.nasa.gov/apod/image/1606/LH7407_LickObservatorySolsticeDawnMoonset_1440x960.jpg",
    "media_type": "image",
    "service_version": "v1",
    "title": "夏至黎明與滿月西沉",
    "url": "http://apod.nasa.gov/apod/image/1606/LH7407_LickObservatorySolsticeDawnMoonset_1024x683.jpg"
}

Error Handle

[LANG] version not found.

The main site(NASA) is the first to update and the most likely to be up-to-date.
For those other languages mirror sites, maybe not alway up-to-date.

If happended, will get error as follow:

apod.get({
    LANG: "fr_fr",
    DATE: '2016-06-24'
}, function(err, data) {
    if (err) {
        console.error(err);
        // 2016-06-24 don't have(or not yet) fr_fr version.
    }
});

Response code not 200

If you get this error, means that the APOD servers cannot be reached.

node-apod's People

Contributors

ssarcandy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-apod's Issues

gl_es craw bug

{
    "date": "2016-06-21",
    "explanation": "\t",
    "hdurl": "http://apod.nasa.gov/apod/image/1606/NGC6814_hubble_3970.jpg",
    "media_type": "image",
    "service_version": "v1",
    "title": "NGC 6814: a galaxia espiral de gran deseño desde o Hubble",
    "url": "http://apod.nasa.gov/apod/image/1606/NGC6814_hubble_960.jpg",
    "lang": "gl_es"
}

more language support

http://apod.nasa.gov/apod/lib/about_apod.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.