initial test with callsign reverse lookup

This commit is contained in:
DJ2LS 2023-07-07 11:56:27 +02:00
parent 43b46cb99b
commit 02793575d0
3 changed files with 77 additions and 4 deletions

View file

@ -1,4 +1,5 @@
const { app, BrowserWindow, ipcMain, dialog, shell } = require("electron");
const https = require('https');
const { autoUpdater } = require("electron-updater");
const path = require("path");
const fs = require("fs");
@ -1048,3 +1049,32 @@ ipcMain.on("request-check-rigctld", (event, data) => {
console.log(e);
}
});
function downloadJsonUrlToFile(url, callsignPath) {
// https://nodejs.org/api/https.html#httpsgetoptions-callback
https.get(url, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
console.log(d);
let json = JSON.parse(d);
fs.writeFileSync(callsignPath, JSON.stringify(json, null, 2));
});
}).on('error', (e) => {
console.error(e);
});
}
function downloadCallsignReverseLookupData(){
var callsignPath = path.join(configFolder, "callsigns.json");
downloadJsonUrlToFile('https://api.freedata.app/callsign_lookup.php', callsignPath)
}
downloadCallsignReverseLookupData();

View file

@ -3865,3 +3865,6 @@ function showOsPopUp(title, message) {
const NOTIFICATION_BODY = message;
new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY });
}

View file

@ -11,6 +11,10 @@ var configFolder = path.join(appDataFolder, "FreeDATA");
var configPath = path.join(configFolder, "config.json");
const config = require(configPath);
var callsignPath = path.join(configFolder, "callsigns.json");
const callsigns = require(callsignPath);
// WINDOW LISTENER
window.addEventListener("DOMContentLoaded", () => {
// startPing button clicked
@ -63,13 +67,36 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => {
var dxcall = document.createElement("td");
var dxcallText = document.createElement("span");
dxcallText.innerText = routes[i]["dxcall"];
dxcall.appendChild(dxcallText);
// check for callsign in callsign list, else use checksum
try{
for (let call in callsigns) {
if(callsigns[call] == routes[i]["dxcall"]){
dxcallText.innerText = routes[i]["dxcall"] + ' (' + call + ')';
}
}
} catch(e){
dxcallText.innerText = routes[i]["dxcall"];
}
dxcallText.appendChild(dxcallText);
var router = document.createElement("td");
var routerText = document.createElement("span");
routerText.innerText = routes[i]["router"];
router.appendChild(routerText);
// check for callsign in callsign list, else use checksum
try{
for (let call in callsigns) {
if(callsigns[call] == routes[i]["router"]){
routerText.innerText = routes[i]["router"] + ' (' + call + ')';
}
}
} catch(e){
routerText.innerText = routes[i]["router"];
}
routerText.appendChild(routerText);
var hops = document.createElement("td");
var hopsText = document.createElement("span");
@ -98,7 +125,7 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => {
/*-------------------------------------------*/
var routes = arg.mesh_signalling_table;
console.log(routes);
//console.log(routes);
if (typeof routes == "undefined") {
return;
}
@ -130,8 +157,21 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => {
var destination = document.createElement("td");
var destinationText = document.createElement("span");
destinationText.innerText = routes[i]["destination"];
// check for callsign in callsign list, else use checksum
try{
for (let call in callsigns) {
if(callsigns[call] == routes[i]["destination"]){
destinationText.innerText = routes[i]["destination"] + ' (' + call + ')';
}
}
} catch(e){
destinationText.innerText = routes[i]["destination"];
}
destination.appendChild(destinationText);
var router = document.createElement("td");
var routerText = document.createElement("span");
routerText.innerText = routes[i]["router"];