Files

100 lines
3.3 KiB
HTML
Raw Permalink Normal View History

2026-02-20 20:10:03 -05:00
<!DOCTYPE html>
<html>
<head>
<!-- This should only be needed once in a rare while to convert data scraped from the Government of Canada website -->
<script src="raw-scraped-data.js"></script>
</head>
<body>
<button id="download-button">Download</button>
<script>
let converted = [];
let min_freq = 9999999;
let max_freq = 0;
scrape_table(t1, 1);
scrape_table(t2, 1000);
scrape_table(t3, 1000000);
console.log(max_freq + "kHz");
console.log(max_freq / 1000 + "MHz");
console.log(max_freq / 1000000 + "GHz");
const downloadButton = document.getElementById('download-button');
downloadButton.addEventListener('click', function () {
// Example data: create a Blob from a string
const textContent = JSON.stringify(converted);
const blob = new Blob([textContent], { type: 'application/json' });
// 3. Create a temporary anchor (<a>) element
const link = document.createElement('a');
// 4. Generate a temporary URL for the blob
const url = URL.createObjectURL(blob);
// 5. Set the anchor's attributes for download
link.href = url;
link.download = 'data.json'; // Specify the default filename
link.style.display = 'none'; // Hide the element
// 6. Append the link to the document body, click it, and remove it
document.body.appendChild(link);
link.click(); // Programmatically trigger the download
// 7. Clean up by revoking the object URL and removing the link
document.body.removeChild(link);
URL.revokeObjectURL(url); // Free up memory
});
function scrape_table(tbl, freq_mult) {
for (let entry of tbl) {
let conv_entry = {};
let freqs = entry.f.split(" - ");
let low_freq = parseFloat(freqs[0].replaceAll(' ', '')) * freq_mult;
let hi_freq = parseFloat(freqs[1].replaceAll(' ', '')) * freq_mult;
min_freq = Math.min(min_freq, low_freq);
max_freq = Math.max(max_freq, hi_freq);
conv_entry.minf = low_freq;
conv_entry.maxf = hi_freq;
let regexp = /primary service\s(?<service>.+?)\send primary service/gm;
// TODO: secondary services are listed after the primary in non-caps,
// are not surrounded by delimiters like primary service
// seems a bit more annoying to match
let result;
let service_cats = {};
let services = [];
// execute the regexp multiple times until we exhaust it,
// creating a new service find each time
while ((result = regexp.exec(entry.d)) != null) {
let service_name = result.groups["service"].replaceAll(' ', '_');
if (service_cats[service_name] == null) {
service_cats[service_name] = 0;
}
service_cats[service_name]++;
services.push(result.groups["service"]);
}
conv_entry.primary = services;
converted.push(conv_entry);
}
}
</script>
</body>
</html>