mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-18 17:49:31 -07:00
better stations list
This commit is contained in:
24
datagenerators/https.js
Normal file
24
datagenerators/https.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// async https wrapper
|
||||
|
||||
const https = require('https');
|
||||
|
||||
module.exports = (url) => new Promise((resolve, reject) => {
|
||||
const headers = {};
|
||||
headers['user-agent'] = '(WeatherStar 4000+ data generator, ws4000@netbymatt.com)';
|
||||
|
||||
https.get(url, {
|
||||
headers,
|
||||
}, res => {
|
||||
if (res.statusCode === 200) {
|
||||
const buffers = [];
|
||||
res.on('data', data => buffers.push(data));
|
||||
res.on('end', () => resolve(Buffer.concat(buffers).toString()));
|
||||
} else {
|
||||
console.log(res);
|
||||
reject(new Error(`Unable to get: ${url}`));
|
||||
}
|
||||
}).on('error', e=> {
|
||||
console.log(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
19547
datagenerators/output/stations - Copy.js
Normal file
19547
datagenerators/output/stations - Copy.js
Normal file
File diff suppressed because it is too large
Load Diff
3334
datagenerators/output/stations.js
Normal file
3334
datagenerators/output/stations.js
Normal file
File diff suppressed because it is too large
Load Diff
53
datagenerators/stations-states.js
Normal file
53
datagenerators/stations-states.js
Normal file
@@ -0,0 +1,53 @@
|
||||
module.exports = [
|
||||
'AZ',
|
||||
'AL',
|
||||
'AK',
|
||||
'AR',
|
||||
'CA',
|
||||
'CO',
|
||||
'CT',
|
||||
'DE',
|
||||
'FL',
|
||||
'GA',
|
||||
'HI',
|
||||
'ID',
|
||||
'IL',
|
||||
'IN',
|
||||
'IA',
|
||||
'KS',
|
||||
'KY',
|
||||
'LA',
|
||||
'ME',
|
||||
'MD',
|
||||
'MA',
|
||||
'MI',
|
||||
'MN',
|
||||
'MS',
|
||||
'MO',
|
||||
'MT',
|
||||
'NE',
|
||||
'NV',
|
||||
'NH',
|
||||
'NJ',
|
||||
'NM',
|
||||
'NY',
|
||||
'NC',
|
||||
'ND',
|
||||
'OH',
|
||||
'OK',
|
||||
'OR',
|
||||
'PA',
|
||||
'RI',
|
||||
'SC',
|
||||
'SD',
|
||||
'TN',
|
||||
'TX',
|
||||
'UT',
|
||||
'VT',
|
||||
'VA',
|
||||
'WA',
|
||||
'WV',
|
||||
'WI',
|
||||
'WY',
|
||||
'PR',
|
||||
];
|
||||
54
datagenerators/stations.js
Normal file
54
datagenerators/stations.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// list all stations in a single file
|
||||
// only find stations with 4 letter codes
|
||||
|
||||
const https = require('./https');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// immediately invoked function so we can access async/await
|
||||
const start = async () => {
|
||||
// load the list of states
|
||||
const states = ['AK', 'NC', 'VA', 'TX', 'GA', 'PR'];
|
||||
// const states = require('./stations-states.js');
|
||||
|
||||
let output = {};
|
||||
// loop through states
|
||||
await Promise.all(states.map(async (state) => {
|
||||
try {
|
||||
// get list and parse the JSON
|
||||
const stationsRaw = await https(`https://api.weather.gov/stations?state=${state}`);
|
||||
const stationsAll = JSON.parse(stationsRaw).features;
|
||||
// filter stations for 4 letter identifiers
|
||||
const stations = stationsAll.filter(station => station.properties.stationIdentifier.match(/^[A-Z]{4}$/));
|
||||
// add each resulting station to the output
|
||||
stations.forEach(station => {
|
||||
const id = station.properties.stationIdentifier;
|
||||
if (output[id]) {
|
||||
console.log(`Duplicate station: ${state}-${id}`);
|
||||
return;
|
||||
}
|
||||
output[id] = {
|
||||
id,
|
||||
city: station.properties.name,
|
||||
state: state,
|
||||
lat: station.geometry.coordinates[1],
|
||||
lon: station.geometry.coordinates[0],
|
||||
};
|
||||
});
|
||||
console.log(`Complete: ${state}`);
|
||||
} catch (e) {
|
||||
console.error(`Unable to get state: ${state}`);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
// write the output
|
||||
fs.writeFileSync(path.join(__dirname, 'output/stations.js'), JSON.stringify(output, null, 2));
|
||||
|
||||
};
|
||||
|
||||
// immediately invoked function allows access to async
|
||||
(async () => {
|
||||
await start();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user