![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@slatham/datapoint
Advanced tools
Readme
Wrapper for the Met Office's DataPoint API - DataPoint
Use your node package manager to install.
npm install @slatham/datapoint
Include in your node project
// import the module
const datapoint = require('@slatham/datapoint');
Define your datapoint API key while instantiating a new Datapoint object. You can register for a key here
const apiKey = xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
const dp = new datapoint(apiKey);
Before using any of the datapoint functionality you must first run the init() function. This is an async operation with a callback function passed as the argument. When called, the datapoint api will be queried for all forecast and observation sites. It will then store these sites in 2 separate quadtrees - one for forecast sites and one for observation sites. This is because these lists rarely change so it saves multiple async calls to the datapoint api for the same data. Also, as the locations are stored in a quadtree data structure they're organised based on their location. This makes queries for nearby sites more efficient. It is recommended to run any call to datapoint in the callback function of the init() function call. That way you'll be sure everything is set up and ready.
dp.init((ready) => {
// YOUR CODE GOES HERE
});
You could even test if everything is working and no errors have occurred during initialisation
dp.init((ready) => {
if(ready) {
// YOUR CODE GOES HERE
} else {
// SOMETHING HAS GONE WRONG
}
});
Retrieve a full listing of all forecast sites (locations) in the UK that are covered. Note that will be a listing of over 5000 sites! The data returned contains a site id. A site id is needed so as you can request a weather forecast for that site id.
dp.init((ready) => {
const allSites = dp.getAllForecastSites();
});
Retrieve a full listing of all observation sites (locations) in the UK that are covered. Note that will be a listing of over 140 sites - much less than the forecast sites. The data returned contains a site id. A site id is needed so as you can request observations for that site id.
dp.init((ready) => {
const allSites = dp.getAllObservationSites();
});
Retrieve a list of nearby forecast locations rather than a full listing. See Wikipedia precision table for a guide on setting the area size for the search.
// location to centre the search around
const location = {latitude: 53.430828, longitude: -2.960830};
// set a size for the area to search
const areaSize = 0.1; // decimal degrees
dp.init((ready) => {
const nearbySites = dp.getNearbyForecastSites(location, areaSize);
});
The queries for nearby sites uses a quadtree data structure for fast retrival. Once init() has run these queries do not hit your datapoint api quota.
Given a coordinate, find the nearest forecast site. You will have a Set() containing a single item returned.
dp.init((ready) => {
// for a given location
const location = {latitude: 53.430828, longitude: -2.960830};
// find the nearest site that datapoint has forecasts for
const nearestSite = dp.getNearestForecastSite(location);
});
Given a coordinate, find the nearest observation site. You will have a Set() containing a single item returned.
dp.init((ready) => {
// for a given location
const location = {latitude: 53.430828, longitude: -2.960830};
// find the nearest site that datapoint has observations for
const nearestSite = dp.getNearestObservationSite(location);
});
Pull a weather forecast for a given site. Remember, you'll have to query for the site id before you can get a forecast or observation. You can pull a 3hourly or daily forecast from the api. You just set what time resolution you require as the second parameter. The first parameter is the ID of the site you're interested in.
const siteId = 322315;
dp.init((ready) => {
// get the 3hourly forecast for the site
dp.getForecast(siteId, '3hourly').then((forecast) => {
console.log(forecast)
});
});
Pull weather observations for a given site. Remember, you'll have to query for the site id before you can get a forecast or observation. Also, the site ID for a forecast location isn't the same as an ID for an observations site. You'll have to query for them as decribed above. You can pull hourly observations for the last 24 hours from the api. The only parameter is the ID of the site you're interested in.
const siteId = 3503;
dp.init((ready) => {
// get the observations for the site
dp.getObservations(siteId).then((observation) => {
console.log(observations)
});
});
Note: The getForecast() and getObservation() are async and return a Promise. This mean you can use "then" and "catch" to handle the promise.
Some full examples to understand usage more fully
Pull the daily forecasts for all nearby sites to a location for a given search area.
// import the module
const datapoint = require('@slatham/datapoint');
// set API key
const apiKey = xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
// instantiate a datapoint object
const dp = new datapoint(apiKey);
// location to centre the search around
const location = {latitude: 53.430828, longitude: -2.960830};
// set a size for the area to search
const areaSize = 0.1; // decimal degrees
dp.init((ready) => {
const nearbySites = dp.getNearbyForecastSites(location, areaSize);
nearbySites.forEach((site) => {
dp.getForecast(site.data.id, 'daily').then((forecast) => {
console.log(forecast)
});
})
});
Careful with this - don't try to query hundreds of sites at once for weather or you'll have your API key blocked for 24 hours!
FAQs
Wrapper for the Met Office's datapoint API
The npm package @slatham/datapoint receives a total of 1 weekly downloads. As such, @slatham/datapoint popularity was classified as not popular.
We found that @slatham/datapoint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.