
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@slatham/datapoint
Advanced tools
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 dp = require('@slatham/datapoint');
Now, the variable dp will hold a datapoint object that can be cached by node. So when you import (as above) in other files, node will use this first cached version.
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 along with your metoffice api key. 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(apiKey, (ready) => {
// YOUR CODE GOES HERE
});
You could even test if everything is working and no errors have occurred during initialisation
dp.init(apiKey, (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(apiKey, (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(apiKey, (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(apiKey, (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(apiKey, (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(apiKey, (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(apiKey, (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(apiKey, (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 dp = require('@slatham/datapoint');
// set API key
const apiKey = xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
// 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(apiKey, (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 2 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.