mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
index module
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// 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');
|
||||
const https = require('./https');
|
||||
|
||||
// immediately invoked function so we can access async/await
|
||||
const start = async () => {
|
||||
@@ -11,7 +11,7 @@ const start = async () => {
|
||||
const states = ['AK', 'NC', 'VA', 'TX', 'GA', 'PR'];
|
||||
// const states = require('./stations-states.js');
|
||||
|
||||
let output = {};
|
||||
const output = {};
|
||||
// loop through states
|
||||
await Promise.all(states.map(async (state) => {
|
||||
try {
|
||||
@@ -19,9 +19,9 @@ const start = async () => {
|
||||
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}$/));
|
||||
const stations = stationsAll.filter((station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/));
|
||||
// add each resulting station to the output
|
||||
stations.forEach(station => {
|
||||
stations.forEach((station) => {
|
||||
const id = station.properties.stationIdentifier;
|
||||
if (output[id]) {
|
||||
console.log(`Duplicate station: ${state}-${id}`);
|
||||
@@ -30,7 +30,7 @@ const start = async () => {
|
||||
output[id] = {
|
||||
id,
|
||||
city: station.properties.name,
|
||||
state: state,
|
||||
state,
|
||||
lat: station.geometry.coordinates[1],
|
||||
lon: station.geometry.coordinates[0],
|
||||
};
|
||||
@@ -44,11 +44,9 @@ const start = async () => {
|
||||
|
||||
// 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