First commit
This commit is contained in:
37
archive.js
Normal file
37
archive.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { readArchiveSince } from "./davis.js";
|
||||
|
||||
// ── Ausgabe ────────────────────────────────────────────────────────────────
|
||||
|
||||
function formatRecord(r) {
|
||||
const ts = r.time.toLocaleString("de-DE", { hour12: false });
|
||||
const tmp = r.tempOut !== null ? `${r.tempOut}°C` : "n/a";
|
||||
const hum = r.humOut !== null ? `${r.humOut}%` : "n/a";
|
||||
const wnd = r.windAvg !== null ? `${r.windAvg} km/h` : "n/a";
|
||||
const dir = r.windDir ?? "n/a";
|
||||
const pre = r.pressure !== null ? `${r.pressure} hPa` : "n/a";
|
||||
const rai = r.rain > 0 ? ` Regen: ${r.rain}mm` : "";
|
||||
return `${ts} Außen: ${tmp} Feuchte: ${hum} Wind: ${wnd} ${dir} Druck: ${pre}${rai}`;
|
||||
}
|
||||
|
||||
// ── CLI ────────────────────────────────────────────────────────────────────
|
||||
// Aufruf: node archive.js [ISO-Datum]
|
||||
// Beispiel: node archive.js 2026-04-01T00:00:00
|
||||
|
||||
let since = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
if (process.argv[2]) {
|
||||
since = new Date(process.argv[2]);
|
||||
if (isNaN(since)) { console.error("Ungültiges Datum:", process.argv[2]); process.exit(1); }
|
||||
}
|
||||
|
||||
console.error(`Lese Archiv ab ${since.toLocaleString("de-DE", { hour12: false })} ...`);
|
||||
|
||||
let lastPct = -1;
|
||||
const records = await readArchiveSince(since, (cur, total) => {
|
||||
const pct = Math.floor(cur / total * 100);
|
||||
if (pct !== lastPct) { process.stderr.write(`\r${pct}% (Seite ${cur}/${total})`); lastPct = pct; }
|
||||
});
|
||||
process.stderr.write("\r\x1b[K");
|
||||
|
||||
console.error(`${records.length} Datensätze gefunden.`);
|
||||
console.log();
|
||||
for (const r of records) console.log(formatRecord(r));
|
||||
Reference in New Issue
Block a user