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:
1
debug/.gitignore
vendored
Normal file
1
debug/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.txt
|
||||||
@@ -3,8 +3,12 @@
|
|||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* npm run debug -- --park greatadventure --date 2026-07-04
|
* 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 { openDb, getApiId } from "../lib/db";
|
||||||
import { PARKS } from "../lib/parks";
|
import { PARKS } from "../lib/parks";
|
||||||
import { scrapeMonthRaw } from "../lib/scrapers/sixflags";
|
import { scrapeMonthRaw } from "../lib/scrapers/sixflags";
|
||||||
@@ -57,30 +61,38 @@ async function main() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nPark : ${park.name} (${park.id})`);
|
// Collect all output so we can write it to a file as well
|
||||||
console.log(`API ID : ${apiId}`);
|
const lines: string[] = [];
|
||||||
console.log(`Date : ${dateStr}`);
|
const out = (...args: string[]) => {
|
||||||
console.log(`\nFetching ${year}-${String(month).padStart(2, "0")} from API...\n`);
|
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);
|
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 targetDate = `${String(month).padStart(2, "0")}/${String(day).padStart(2, "0")}/${year}`;
|
||||||
const dayData = raw.dates.find((d) => d.date === targetDate);
|
const dayData = raw.dates.find((d) => d.date === targetDate);
|
||||||
|
|
||||||
if (!dayData) {
|
if (!dayData) {
|
||||||
console.error(`Date ${dateStr} not found in API response.`);
|
console.error(`Date ${dateStr} not found in API response.`);
|
||||||
console.log(`\nDates returned by API:`);
|
console.error(`Dates returned by API: ${raw.dates.map((d) => d.date).join(", ")}`);
|
||||||
for (const d of raw.dates) console.log(` ${d.date}`);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Raw API response for this day ─────────────────────────────────────────
|
// ── Raw API response ───────────────────────────────────────────────────────
|
||||||
console.log("── Raw API response ─────────────────────────────────────────");
|
out("");
|
||||||
console.log(JSON.stringify(dayData, null, 2));
|
out("── Raw API response ─────────────────────────────────────────");
|
||||||
|
out(JSON.stringify(dayData, null, 2));
|
||||||
|
|
||||||
// ── Parsed result (what the scraper stores) ───────────────────────────────
|
// ── Parsed result ──────────────────────────────────────────────────────────
|
||||||
console.log("\n── Parsed result ────────────────────────────────────────────");
|
|
||||||
const operating =
|
const operating =
|
||||||
dayData.operatings?.find((o) => o.operatingTypeName === "Park") ??
|
dayData.operatings?.find((o) => o.operatingTypeName === "Park") ??
|
||||||
dayData.operatings?.[0];
|
dayData.operatings?.[0];
|
||||||
@@ -91,18 +103,26 @@ async function main() {
|
|||||||
: undefined;
|
: undefined;
|
||||||
const isOpen = !dayData.isParkClosed && hoursLabel !== undefined;
|
const isOpen = !dayData.isParkClosed && hoursLabel !== undefined;
|
||||||
|
|
||||||
console.log(` isParkClosed : ${dayData.isParkClosed}`);
|
out("");
|
||||||
console.log(` operatings : ${dayData.operatings?.length ?? 0} entr${dayData.operatings?.length === 1 ? "y" : "ies"}`);
|
out("── Parsed result ────────────────────────────────────────────");
|
||||||
|
out(` isParkClosed : ${dayData.isParkClosed}`);
|
||||||
|
out(` operatings : ${dayData.operatings?.length ?? 0} entr${dayData.operatings?.length === 1 ? "y" : "ies"}`);
|
||||||
if (operating) {
|
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) {
|
if (item) {
|
||||||
console.log(` timeFrom : ${item.timeFrom} → ${fmt24(item.timeFrom)}`);
|
out(` timeFrom : ${item.timeFrom} → ${fmt24(item.timeFrom)}`);
|
||||||
console.log(` timeTo : ${item.timeTo} → ${fmt24(item.timeTo)}`);
|
out(` timeTo : ${item.timeTo} → ${fmt24(item.timeTo)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(` hoursLabel : ${hoursLabel ?? "(none)"}`);
|
out(` hoursLabel : ${hoursLabel ?? "(none)"}`);
|
||||||
console.log(` isOpen : ${isOpen}`);
|
out(` isOpen : ${isOpen}`);
|
||||||
console.log();
|
|
||||||
|
// ── 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) => {
|
main().catch((err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user