Skip to content

Instantly share code, notes, and snippets.

@Lily418
Created September 16, 2021 14:25
Show Gist options
  • Save Lily418/02df70366356d124ca1ce8a50ce9be73 to your computer and use it in GitHub Desktop.
Save Lily418/02df70366356d124ca1ce8a50ce9be73 to your computer and use it in GitHub Desktop.
var promisify = require("promisify-node");
const fseAirports = require("./icaodata-with-zones.json")
const fs = require('fs')
const sqlite = require('sqlite')
const sqlite3 = require('sqlite3')
const dbPromise = sqlite.open({
filename: 'little_navmap_navigraph.sqlite',
driver: sqlite3.Database
})
const f = async () => {
const db = await dbPromise
const p = Object.keys(fseAirports).map(async (key, index) => {
const airport = fseAirports[key]
const icao = airport.icao
const msfs = airport.msfs
let ident = undefined
if (msfs.length === 1 && msfs[0] !== null) {
ident = msfs[0]
} else if (icao) {
ident = icao
} else {
ident = key
}
const airportRow = await db.get(`SELECT * FROM airport WHERE ident='${ident}'`)
const airportInDatabase = airportRow
const ilsRunways = await db.all(`SELECT * FROM ils WHERE loc_airport_ident='${ident}'`)
if (ilsRunways.length) {
const ilsRunwayNames = ilsRunways.map((row) => row.loc_runway_name)
fseAirports[key].hasILS = ilsRunwayNames
} else if(airportInDatabase) {
fseAirports[key].hasILS = []
} else {
fseAirports[key].hasILS = undefined
}
})
await(Promise.all(p))
fs.writeFile("./icaodata-with-zones-and-ils.json", JSON.stringify(fseAirports, undefined, 2), () => {
console.log("Wrote icaodata-with-zones-and-ils.json")
})
}
f()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment