115 lines
3.6 KiB
JavaScript
115 lines
3.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Re-descarga las secciones que dieron error 500.
|
|
* Hace login fresco + descarga solo las faltantes.
|
|
*/
|
|
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
import { chromium } from "playwright";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const SECCIONES_DIR = path.join(__dirname, "descargas", "secciones");
|
|
const SESSION_FILE = path.join(__dirname, "session.json");
|
|
|
|
const CREDENTIALS = {
|
|
username: "saldis_karina@hotmail.com",
|
|
password: "Martes13#",
|
|
};
|
|
|
|
const CAMPUS_BASE = "https://voley.onlineeducation.center/es/campus/student/training/e/14197";
|
|
const MODULO_1 = "m/19096";
|
|
|
|
const FALTANTES = [
|
|
{ modulo: "Modulo_1_Planificacion", nombre: "Seguimientos_Equipos", id: "s/35523" },
|
|
{ modulo: "Modulo_1_Planificacion", nombre: "Analisis_Equipos_1", id: "s/35524" },
|
|
{ modulo: "Modulo_1_Planificacion", nombre: "Analisis_Equipos_2", id: "s/35525" },
|
|
{ modulo: "Modulo_1_Planificacion", nombre: "TP_Final_Unidad", id: "s/35526" },
|
|
];
|
|
|
|
function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
|
|
|
|
async function main() {
|
|
console.log("🔄 Re-descargando secciones faltantes con login fresco...\n");
|
|
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
|
});
|
|
|
|
const context = await browser.newContext({
|
|
viewport: { width: 1280, height: 900 },
|
|
locale: "es-AR",
|
|
});
|
|
|
|
const page = await context.newPage();
|
|
|
|
// Login
|
|
console.log("🔑 Haciendo login...");
|
|
await page.goto(`${CAMPUS_BASE}/${MODULO_1}/s/35523/study-resources/list`, {
|
|
waitUntil: "networkidle",
|
|
timeout: 30000,
|
|
});
|
|
|
|
const url = page.url();
|
|
if (!url.includes("/campus/")) {
|
|
// Need to login
|
|
try {
|
|
await page.waitForSelector("#login-email", { timeout: 10000 });
|
|
await page.fill("#login-email", CREDENTIALS.username);
|
|
await page.fill("#login-password", CREDENTIALS.password);
|
|
await page.click("#btn-login");
|
|
await page.waitForURL("**/campus/**", { timeout: 30000 });
|
|
console.log(" ✅ Login exitoso\n");
|
|
|
|
// Guardar sesión actualizada
|
|
await context.storageState({ path: SESSION_FILE });
|
|
console.log(" ✅ Sesión actualizada en session.json\n");
|
|
} catch (err) {
|
|
console.error(` ❌ Error en login: ${err.message}`);
|
|
await browser.close();
|
|
process.exit(1);
|
|
}
|
|
} else {
|
|
console.log(" ✅ Ya autenticado\n");
|
|
}
|
|
|
|
// Descargar cada sección
|
|
for (const sec of FALTANTES) {
|
|
const secUrl = `${CAMPUS_BASE}/${MODULO_1}/${sec.id}/study-resources/list`;
|
|
const destDir = path.join(SECCIONES_DIR, sec.modulo, sec.nombre);
|
|
const destFile = path.join(destDir, "pagina.html");
|
|
|
|
console.log(`📥 ${sec.nombre}...`);
|
|
|
|
try {
|
|
await page.goto(secUrl, { waitUntil: "networkidle", timeout: 30000 });
|
|
await sleep(2000);
|
|
const html = await page.content();
|
|
|
|
if (html.includes("500 Internal Server Error") || html.includes("An Error Occurred")) {
|
|
console.log(` ⚠ Sigue con error 500 en el campus`);
|
|
continue;
|
|
}
|
|
|
|
if (html.includes("login-email") || html.includes("auth0-lock")) {
|
|
console.log(` ⚠ Redirigió al login, sesión expirada`);
|
|
continue;
|
|
}
|
|
|
|
fs.mkdirSync(destDir, { recursive: true });
|
|
fs.writeFileSync(destFile, html);
|
|
const size = fs.statSync(destFile).size;
|
|
console.log(` ✅ Descargado (${(size / 1024).toFixed(1)} KB)`);
|
|
} catch (err) {
|
|
console.log(` ❌ Error: ${err.message}`);
|
|
}
|
|
}
|
|
|
|
await browser.close();
|
|
console.log("\n✅ Listo. Ejecutá: node generar_dashboard.mjs");
|
|
}
|
|
|
|
main();
|