fix missing states in station list

This commit is contained in:
Matt Walsh
2025-05-12 10:47:43 -05:00
parent 13f08b62cc
commit 97f96d4091
5 changed files with 22710 additions and 35868 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -9,61 +9,59 @@ import chunk from './chunk.mjs';
// skip stations starting with these letters // skip stations starting with these letters
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J']; const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
// immediately invoked function so we can access async/await // chunk the list of states
const start = async () => { const chunkStates = chunk(states, 1);
// chunk the list of states
const chunkStates = chunk(states, 5);
// store output // store output
const output = {}; const output = {};
// process all chunks // process all chunks
for (let i = 0; i < chunkStates.length; i += 1) { for (let i = 0; i < chunkStates.length; i += 1) {
const stateChunk = chunkStates[i]; const stateChunk = chunkStates[i];
// loop through states // loop through states
stateChunk.forEach(async (state) => { // eslint-disable-next-line no-await-in-loop
try { await Promise.allSettled(stateChunk.map(async (state) => {
let stations; try {
let next = `https://api.weather.gov/stations?state=${state}`; let stations;
do { let next = `https://api.weather.gov/stations?state=${state}`;
// get list and parse the JSON let round = 0;
// eslint-disable-next-line no-await-in-loop do {
const stationsRaw = await https(next); console.log(`Getting: ${state}-${round}`);
stations = JSON.parse(stationsRaw); // get list and parse the JSON
// filter stations for 4 letter identifiers // eslint-disable-next-line no-await-in-loop
const stationsFiltered4 = stations.features.filter((station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/)); const stationsRaw = await https(next);
// filter against starting letter stations = JSON.parse(stationsRaw);
const stationsFiltered = stationsFiltered4.filter((station) => !skipStations.includes(station.properties.stationIdentifier.slice(0, 1))); // filter stations for 4 letter identifiers
// add each resulting station to the output const stationsFiltered4 = stations.features.filter((station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/));
stationsFiltered.forEach((station) => { // filter against starting letter
const id = station.properties.stationIdentifier; const stationsFiltered = stationsFiltered4.filter((station) => !skipStations.includes(station.properties.stationIdentifier.slice(0, 1)));
if (output[id]) { // add each resulting station to the output
console.log(`Duplicate station: ${state}-${id}`); stationsFiltered.forEach((station) => {
return; const id = station.properties.stationIdentifier;
} if (output[id]) {
output[id] = { console.log(`Duplicate station: ${state}-${id}`);
id, return;
city: station.properties.name, }
state, output[id] = {
lat: station.geometry.coordinates[1], id,
lon: station.geometry.coordinates[0], city: station.properties.name,
}; state,
}); lat: station.geometry.coordinates[1],
next = stations?.pagination?.next; lon: station.geometry.coordinates[0],
// write the output };
writeFileSync('./datagenerators/output/stations.json', JSON.stringify(output, null, 2)); });
} next = stations?.pagination?.next;
while (next && stations.features.length > 0); round += 1;
console.log(`Complete: ${state}`); // write the output
return true; writeFileSync('./datagenerators/output/stations.json', JSON.stringify(output, null, 2));
} catch (e) {
console.error(`Unable to get state: ${state}`);
return false;
} }
}); while (next && stations.features.length > 0);
} console.log(`Complete: ${state}`);
}; return true;
} catch (e) {
// immediately invoked function allows access to async console.error(`Unable to get state: ${state}`);
await start(); return false;
}
}));
}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "ws4kp", "name": "ws4kp",
"version": "5.16.5", "version": "5.16.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ws4kp", "name": "ws4kp",
"version": "5.16.5", "version": "5.16.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"ejs": "^3.1.5", "ejs": "^3.1.5",

File diff suppressed because it is too large Load Diff