mirror of
https://github.com/cosinekitty/astronomy.git
synced 2025-12-30 02:58:42 -05:00
Created test data using a Windows batch file that downloads moon phase data from the US Navy Astronomical Applications API, then converts the resulting JSON into a flat text file. This has every moon phase for every tenth calendar year between 1800 and 2100. I'm keeping the scripts for reference, but I'm checking in the test data to the repo for repeated use in a unit test to be created.
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
/*
|
|
parse_moon_phases.js
|
|
*/
|
|
const fs = require('fs');
|
|
|
|
listing = '';
|
|
|
|
for (let filename of fs.readdirSync('.')) {
|
|
let m = filename.match(/^(\d{4})\.json$/);
|
|
if (m) {
|
|
let year = parseInt(m[1]);
|
|
//console.log(year);
|
|
let text = fs.readFileSync(filename, {encoding:'utf8'});
|
|
let data = JSON.parse(text);
|
|
if (data.error !== false) {
|
|
console.log(`ERROR: found error flag (or flag is missing) in file ${filename}`);
|
|
process.exit(1);
|
|
}
|
|
if (data.year !== year) {
|
|
console.log(`ERROR: data.year=${data.year} in file ${filename}`);
|
|
process.exit(1);
|
|
}
|
|
if (!(data.phasedata instanceof Array)) {
|
|
console.log(`ERROR: Missing phasedata array in ${filename}`);
|
|
process.exit(1);
|
|
}
|
|
for (let item of data.phasedata) {
|
|
let when = new Date(`${item.date} ${item.time}Z`);
|
|
let phase = ['New Moon', 'First Quarter', 'Full Moon', 'Last Quarter'].indexOf(item.phase);
|
|
if (phase < 0) {
|
|
console.log(`ERROR: unknown lunar phase name "${item.phase}" in file ${filename}`);
|
|
process.exit(1);
|
|
}
|
|
listing += `${phase} ${when.toISOString()}\n`;
|
|
}
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync('moonphases.txt', listing);
|
|
process.exit(0);
|