fix missing states in station list

This commit is contained in:
Matt Walsh 2025-05-12 10:47:43 -05:00
commit 97f96d4091
No known key found for this signature in database
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,24 +9,25 @@ 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
await Promise.allSettled(stateChunk.map(async (state) => {
try { try {
let stations; let stations;
let next = `https://api.weather.gov/stations?state=${state}`; let next = `https://api.weather.gov/stations?state=${state}`;
let round = 0;
do { do {
console.log(`Getting: ${state}-${round}`);
// get list and parse the JSON // get list and parse the JSON
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const stationsRaw = await https(next); const stationsRaw = await https(next);
@ -51,6 +52,7 @@ const start = async () => {
}; };
}); });
next = stations?.pagination?.next; next = stations?.pagination?.next;
round += 1;
// write the output // write the output
writeFileSync('./datagenerators/output/stations.json', JSON.stringify(output, null, 2)); writeFileSync('./datagenerators/output/stations.json', JSON.stringify(output, null, 2));
} }
@ -61,9 +63,5 @@ const start = async () => {
console.error(`Unable to get state: ${state}`); console.error(`Unable to get state: ${state}`);
return false; return false;
} }
}); }));
} }
};
// immediately invoked function allows access to async
await start();

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