0.2.1 • Published 8 years ago

datapoint-js v0.2.1

Weekly downloads
5
License
GPLv3
Repository
github
Last release
8 years ago

DataPoint for JavaScript Build Status

A JavaScript library for accessing weather data via the Met Office's open data API known as DataPoint.

Disclaimer: This module is in no way part of the DataPoint project/service. This module is intended to simplify the use of DataPoint for JavaScript projects. No support for this module is provided by the Met Office and may break as the DataPoint service grows/evolves. The author will make reasonable efforts to keep it up to date and fully featured.

Features

  • List forecast/observation sites
  • Get nearest forecast/observation site from longitude and latitiude
  • Get the following 5 day forecast types for any site
  • Daily (Two timesteps, midday and midnight UTC)
  • 3 hourly (Eight timesteps, every 3 hours starting at midnight UTC)
  • Get hourly observations for the last 48 hours

Installation

Node

npm install datapoint-js

Browser

bower install datapoint-js

Manual

Download the contents of either /src (for node) or /dist/browser (for browser) and include them in your project.

Example Usage

Node

var datapoint = require('datapoint-js')

datapoint.set_key("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")

site = datapoint.get_nearest_forecast_site(-0.124626, 51.500728)

forecast = datapoint.get_forecast_for_site(site.id, "3hourly")

current_timestep = forecast.days[0].timesteps[0]

console.log("Temperature is " + current_timestep.temperature.value + "°" + current_timestep.temperature.units + " in " + site.name)

Output

Temperature is 15°C in London

Browser

<html>
<head>
  <title>Datapoint test</title>
</head>
<body>

  <h1>Weather</h1>
  <p id="weather">Loading...</p>

  <script src="../dist/browser/datapoint.js"></script>
  <script>

    datapoint.set_key("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");

    site = datapoint.get_nearest_forecast_site(-0.124626, 51.500728);

    forecast = datapoint.get_forecast_for_site(site.id);

    current_timestep = forecast.days[0].timesteps[0];

    document.getElementById("weather").innerHTML =
        "Temperature is " + current_timestep.temperature.value + "&deg;" + current_timestep.temperature.units + " in " + site.name;

  </script>
</body>
</html>

Output

The contents of the <p> block is replaced with Temperature is 15°C in London.

Contributing changes

Please feel free to submit issues and pull requests.

To work on the project simply clone the project and run npm install.

This project uses gulp as its task runner and can be used to browserify the code and generate the documentation.

Documentation

Documentation is automatically generated using JSDoc and is stored in docs.

To regenerate the documentation simply run

gulp document

License

GPL v3

0.2.1

8 years ago

0.1.1

9 years ago