feat: save debug output to debug/{parkId}_{date}.txt
All checks were successful
Build and Deploy / Build & Push (push) Successful in 5m13s
All checks were successful
Build and Deploy / Build & Push (push) Successful in 5m13s
Creates debug/ folder (txt files gitignored). Output is printed to the terminal and written to the file simultaneously. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,12 @@
|
||||
*
|
||||
* Usage:
|
||||
* npm run debug -- --park greatadventure --date 2026-07-04
|
||||
*
|
||||
* Output is printed to the terminal and saved to debug/{parkId}_{date}.txt
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { openDb, getApiId } from "../lib/db";
|
||||
import { PARKS } from "../lib/parks";
|
||||
import { scrapeMonthRaw } from "../lib/scrapers/sixflags";
|
||||
@@ -57,30 +61,38 @@ async function main() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`\nPark : ${park.name} (${park.id})`);
|
||||
console.log(`API ID : ${apiId}`);
|
||||
console.log(`Date : ${dateStr}`);
|
||||
console.log(`\nFetching ${year}-${String(month).padStart(2, "0")} from API...\n`);
|
||||
// Collect all output so we can write it to a file as well
|
||||
const lines: string[] = [];
|
||||
const out = (...args: string[]) => {
|
||||
const line = args.join(" ");
|
||||
lines.push(line);
|
||||
console.log(line);
|
||||
};
|
||||
|
||||
out(`Park : ${park.name} (${park.id})`);
|
||||
out(`API ID : ${apiId}`);
|
||||
out(`Date : ${dateStr}`);
|
||||
out(`Fetched : ${new Date().toISOString()}`);
|
||||
out("");
|
||||
out(`Fetching ${year}-${String(month).padStart(2, "0")} from API...`);
|
||||
|
||||
const raw = await scrapeMonthRaw(apiId, year, month);
|
||||
|
||||
// Find the specific day in the response
|
||||
const targetDate = `${String(month).padStart(2, "0")}/${String(day).padStart(2, "0")}/${year}`;
|
||||
const dayData = raw.dates.find((d) => d.date === targetDate);
|
||||
|
||||
if (!dayData) {
|
||||
console.error(`Date ${dateStr} not found in API response.`);
|
||||
console.log(`\nDates returned by API:`);
|
||||
for (const d of raw.dates) console.log(` ${d.date}`);
|
||||
console.error(`Dates returned by API: ${raw.dates.map((d) => d.date).join(", ")}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// ── Raw API response for this day ─────────────────────────────────────────
|
||||
console.log("── Raw API response ─────────────────────────────────────────");
|
||||
console.log(JSON.stringify(dayData, null, 2));
|
||||
// ── Raw API response ───────────────────────────────────────────────────────
|
||||
out("");
|
||||
out("── Raw API response ─────────────────────────────────────────");
|
||||
out(JSON.stringify(dayData, null, 2));
|
||||
|
||||
// ── Parsed result (what the scraper stores) ───────────────────────────────
|
||||
console.log("\n── Parsed result ────────────────────────────────────────────");
|
||||
// ── Parsed result ──────────────────────────────────────────────────────────
|
||||
const operating =
|
||||
dayData.operatings?.find((o) => o.operatingTypeName === "Park") ??
|
||||
dayData.operatings?.[0];
|
||||
@@ -91,18 +103,26 @@ async function main() {
|
||||
: undefined;
|
||||
const isOpen = !dayData.isParkClosed && hoursLabel !== undefined;
|
||||
|
||||
console.log(` isParkClosed : ${dayData.isParkClosed}`);
|
||||
console.log(` operatings : ${dayData.operatings?.length ?? 0} entr${dayData.operatings?.length === 1 ? "y" : "ies"}`);
|
||||
out("");
|
||||
out("── Parsed result ────────────────────────────────────────────");
|
||||
out(` isParkClosed : ${dayData.isParkClosed}`);
|
||||
out(` operatings : ${dayData.operatings?.length ?? 0} entr${dayData.operatings?.length === 1 ? "y" : "ies"}`);
|
||||
if (operating) {
|
||||
console.log(` selected : "${operating.operatingTypeName}" (${operating.items?.length ?? 0} item(s))`);
|
||||
out(` selected : "${operating.operatingTypeName}" (${operating.items?.length ?? 0} item(s))`);
|
||||
if (item) {
|
||||
console.log(` timeFrom : ${item.timeFrom} → ${fmt24(item.timeFrom)}`);
|
||||
console.log(` timeTo : ${item.timeTo} → ${fmt24(item.timeTo)}`);
|
||||
out(` timeFrom : ${item.timeFrom} → ${fmt24(item.timeFrom)}`);
|
||||
out(` timeTo : ${item.timeTo} → ${fmt24(item.timeTo)}`);
|
||||
}
|
||||
}
|
||||
console.log(` hoursLabel : ${hoursLabel ?? "(none)"}`);
|
||||
console.log(` isOpen : ${isOpen}`);
|
||||
console.log();
|
||||
out(` hoursLabel : ${hoursLabel ?? "(none)"}`);
|
||||
out(` isOpen : ${isOpen}`);
|
||||
|
||||
// ── Write to file ──────────────────────────────────────────────────────────
|
||||
const debugDir = path.join(process.cwd(), "debug");
|
||||
fs.mkdirSync(debugDir, { recursive: true });
|
||||
const outPath = path.join(debugDir, `${parkId}_${dateStr}.txt`);
|
||||
fs.writeFileSync(outPath, lines.join("\n") + "\n");
|
||||
console.log(`\nSaved to debug/${parkId}_${dateStr}.txt`);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
||||
Reference in New Issue
Block a user