ADSB backfill fix?
This commit is contained in:
@@ -190,7 +190,11 @@ async function scrapeHexDatabase(icao) {
|
|||||||
const resp = await fetch(url);
|
const resp = await fetch(url);
|
||||||
if (!resp.ok) return null;
|
if (!resp.ok) return null;
|
||||||
|
|
||||||
const $ = cheerio.load(await resp.text());
|
const html = await resp.text();
|
||||||
|
const tableMatch = html.match(/<table[\s\S]*?<\/table>/i);
|
||||||
|
if (!tableMatch) return null;
|
||||||
|
|
||||||
|
const $ = cheerio.load(tableMatch[0]);
|
||||||
const row = $('tr').filter((_, el) => $(el).text().toLowerCase().includes(icao.toLowerCase())).first();
|
const row = $('tr').filter((_, el) => $(el).text().toLowerCase().includes(icao.toLowerCase())).first();
|
||||||
if (!row.length) return null;
|
if (!row.length) return null;
|
||||||
|
|
||||||
@@ -229,7 +233,7 @@ export async function enrichAircraft(a) {
|
|||||||
|
|
||||||
// 1. Check own DB first
|
// 1. Check own DB first
|
||||||
const row = db.prepare('SELECT * FROM aircraft WHERE icao = ?').get(icao);
|
const row = db.prepare('SELECT * FROM aircraft WHERE icao = ?').get(icao);
|
||||||
if(row?.manufacturer && row?.model) return { ...a, ...row, type: classifyAircraft(row) };
|
if(row?.aircraft) return { ...a, ...row, type: classifyAircraft(row) };
|
||||||
|
|
||||||
// 2. Race the two external sources
|
// 2. Race the two external sources
|
||||||
if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' };
|
if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' };
|
||||||
|
|||||||
Reference in New Issue
Block a user