Enhance logging with student details in evaluation
Updated `iterateOverDashboardTable.js` to include student name and ID in log output. Added functions in `evaluateStartPakket.js` to fetch student name and ID from specified selectors. Adjusted `.gitignore` to exclude `.idea` directory.
This commit is contained in:
@@ -6,9 +6,10 @@ start dan het script
|
||||
*/
|
||||
const puppeteer = require("puppeteer");
|
||||
const isStartPakketAvailable = require("./evaluateStartPakket");
|
||||
const xlsx = require("xlsx");
|
||||
const fs = require("fs");
|
||||
const saveResultsToExcel = require("./saveResultsToExcel");
|
||||
const appendToExcel = require("./appendResultsToExcel");
|
||||
const wait = require("./wait");
|
||||
|
||||
async function iterateOverDashboardTable() {
|
||||
/*connection to local host */
|
||||
@@ -18,6 +19,7 @@ async function iterateOverDashboardTable() {
|
||||
|
||||
//array to store results for Excel export
|
||||
let results = []
|
||||
const filename = "DashboardResults.xlsx"
|
||||
|
||||
// Get all open pages (tabs)
|
||||
const pages = await browser.pages();
|
||||
@@ -55,6 +57,12 @@ async function iterateOverDashboardTable() {
|
||||
);
|
||||
console.log(`Found ${links.length} AA-links to process.`);
|
||||
|
||||
// Initialize Excel file if it doesn't exist
|
||||
if (!fs.existsSync(filename)) {
|
||||
saveResultsToExcel([], filename); // Create empty file
|
||||
console.log(`Initialized new Excel file: ${filename}`);
|
||||
}
|
||||
|
||||
// process links
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
console.log(`Processing link ${i + 1}`);
|
||||
@@ -68,6 +76,8 @@ async function iterateOverDashboardTable() {
|
||||
`${tableBodySelector} tr span[title="AA-rapport"] a`
|
||||
);
|
||||
|
||||
if ((i + 1) % 10 === 0) {await wait(10000)}
|
||||
|
||||
const [newPagePromise] = await Promise.all([
|
||||
new Promise((resolve) =>
|
||||
browser.once("targetcreated", async (target) => {
|
||||
@@ -77,6 +87,7 @@ async function iterateOverDashboardTable() {
|
||||
),
|
||||
links[i].click(), // Simulate the click
|
||||
]);
|
||||
let result;
|
||||
|
||||
const newPage = await newPagePromise;
|
||||
|
||||
@@ -84,7 +95,7 @@ async function iterateOverDashboardTable() {
|
||||
const evaluationResult = await isStartPakketAvailable(newPage);
|
||||
|
||||
//Save results for Excel
|
||||
results.push({
|
||||
result = ({
|
||||
LinkNumber: i +1,
|
||||
StudentName: evaluationResult.studName || 'N/A',
|
||||
StudentID: evaluationResult.studId || "N/A",
|
||||
@@ -97,7 +108,7 @@ async function iterateOverDashboardTable() {
|
||||
} catch (error) {
|
||||
console.error(`Error processing link ${i + 1}:`, error.message);
|
||||
// Save error for Excel
|
||||
results.push({
|
||||
result = ({
|
||||
LinkNumber: i + 1,
|
||||
StudentName: "Error",
|
||||
StudentID: "Error",
|
||||
@@ -109,6 +120,8 @@ async function iterateOverDashboardTable() {
|
||||
finally {
|
||||
await newPage.close();
|
||||
}
|
||||
results.push(result);
|
||||
appendToExcel(result, filename);
|
||||
}
|
||||
|
||||
console.log("All links processed.");
|
||||
|
||||
Reference in New Issue
Block a user