Giter VIP home page Giter VIP logo

yr.no-forecast's Introduction

yr.no-forecast

TravisCI npm version Coverage Status

Wrapper to easily get weather data for a specified location in JSON format. Uses yr.no-interface under the hood. See the API docs at yr.no.

Usage

Use the getWeather(queryParams) function to get a LocationForecast object by calling the "locationforecast" API.

Here's an example:

const yrno = require('yr.no-forecast')({
  version: '1.9', // this is the default if not provided,
  request: {
    // make calls to locationforecast timeout after 15 seconds
    timeout: 15000
  }
});

const LOCATION = {
  // This is Dublin, Ireland
  lat: 53.3478,
  lon: 6.2597
};

yrno.getWeather(LOCATION)
  .then((weather) => {
    // Get general weather for next five days (Array with five objects)
    weather.getFiveDaySummary()
      .then((data) => console.log('five day summary', data));

    // Get a weather data point for a given time between now and 9 days ahead
    weather.getForecastForTime(new Date())
      .then((data) => console.log('current weather', data));
  })
  .catch((e) => {
    console.log('an error occurred!', e);
  });

API

module(config)

This module exports a single factory function that can be used to get a configured instance that exports the getWeather function.

Currently supported config options:

  • version - Passed when making a call to the met.no API to select the locationforecast version to call
  • request - Can be populated with options for the request module. The only setting that you should need to pass is timeout and is demonstrated above

instance.getWeather(params[, version])

Returns a Promise that will resolve with a LocationForecast object that contains functions to get weather data. You can pass the version parameter if you want to override the default of 1.9, or the default you supplied when creating and instance.

LocationForecast.getFiveDaySummary()

Returns a Promise that resolves to an Array of 5 weather data Objects.

LocationForecast.getForecastForTime(time)

Returns a Promise that resolves to a weather data Object that is closest to the provided time argument. The time argument will be passed to moment.utc so many time formats will work, but a millisecond timestamp or ISO formatted date string are both ideal options to use use.

LocationForecast.getXml()

Returns the raw XML string that the locationforecast API returned.

LocationForecast.getJson()

Returns the JSON representation of the entire locationforecast response.

LocationForecast.getFirstDateInPayload()

Returns the first date string that is available in the data returned from the locationforecast call.

LocationForecast.getValidTimes()

Returns an Array of ISO timestamps that represent points in time that we have weather data for.

Weather JSON Format

Some fields will be undefined depending on the weather conditions. Always verify the field you need exists, e.g use data.hasOwnProperty('fog') or similar techniques.

{
  "datatype": "forecast",
  "from": "2017-04-18T03:00:00Z",
  "to": "2017-04-18T03:00:00Z",
  "icon": "PartlyCloud",
  "rain": "0.0 mm",
  "altitude": "0",
  "latitude": "59.8940",
  "longitude": "10.6450",
  "temperature": {
    "id": "TTT",
    "unit": "celsius",
    "value": "-0.9"
  },
  "windDirection": {
    "id": "dd",
    "deg": "14.6",
    "name": "N"
  },
  "windSpeed": {
    "id": "ff",
    "mps": "1.5",
    "beaufort": "1",
    "name": "Flau vind"
  },
  "windGust": {
    "id": "ff_gust",
    "mps": "2.4"
  },
  "humidity": {
    "value": "78.3",
    "unit": "percent"
  },
  "pressure": {
    "id": "pr",
    "unit": "hPa",
    "value": "1030.1"
  },
  "cloudiness": {
    "id": "NN",
    "percent": "15.4"
  },
  "fog": {
    "id": "FOG",
    "percent": "0.0"
  },
  "lowClouds": {
    "id": "LOW",
    "percent": "15.4"
  },
  "mediumClouds": {
    "id": "MEDIUM",
    "percent": "0.8"
  },
  "highClouds": {
    "id": "HIGH",
    "percent": "0.0"
  },
  "dewpointTemperature": {
    "id": "TD",
    "unit": "celsius",
    "value": "-4.5"
  }
}

CHANGELOG

Can be found at this link.

yr.no-forecast's People

Contributors

bitti09 avatar evanshortiss avatar kvasbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yr.no-forecast's Issues

MSL Missing

Hi there,

Thanks for this great script! The only thing that I'm missing from the API is the MSL specification, it makes a huge difference outside or Norway:

E.g. if you compare:
http://api.yr.no/weatherapi/locationforecast/1.9/?lat=47.4143;lon=9.744417
vs the actual height of this location:
http://api.yr.no/weatherapi/locationforecast/1.9/?lat=47.4143;lon=9.744417;msl=430

Alternatively this highchart:

uses:
http://www.yr.no/place/Austria/Vorarlberg/Dornbirn/forecast_hour_by_hour.xml
and there also seems to be:
http://www.yr.no/place/Austria/Vorarlberg/Dornbirn/forecast.xml

but this is not documented anywhere on the normal API page...

Anyway, thanks a lot for the script :)

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.