Second Beta Version complete
Enhanced VZP checking
This commit is contained in:
parent
47c4afa99e
commit
1f5fcbe3c8
|
@ -1,10 +1,13 @@
|
|||
// Vars
|
||||
const isPromise = require("./ispromise")
|
||||
|
||||
const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]';
|
||||
const CELL_SELECTOR =
|
||||
'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
|
||||
const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]'
|
||||
const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]'
|
||||
const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]'
|
||||
'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
|
||||
const CELL_SELECTOR_OPEN = "a[title='Sectie samenvouwen Algemene opleidingsonderdelen']";
|
||||
const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]';
|
||||
const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]';
|
||||
const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]';
|
||||
const STPKT_KEUZE_CELL_SELECTOR_OPEN = 'a[title="Sectie samenvouwen Keuzeopleidingsonderdelen"]'
|
||||
|
||||
/**
|
||||
* Extracted function to get the text content of a node.
|
||||
|
@ -39,9 +42,23 @@ async function getContentFrame(page) {
|
|||
*/
|
||||
async function isStartPakketAvailable(page) {
|
||||
const contentFrame = await getContentFrame(page);
|
||||
await contentFrame.waitForSelector(CELL_SELECTOR);
|
||||
const cell = await contentFrame.$(CELL_SELECTOR);
|
||||
const cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR)
|
||||
let cell
|
||||
let isCollapsed_main_before_function = true
|
||||
try {
|
||||
await contentFrame.waitForSelector(CELL_SELECTOR, { timeout: 5000 }); // Adjust timeout as needed
|
||||
cell = await contentFrame.$(CELL_SELECTOR);
|
||||
} catch (error) {
|
||||
console.warn("CELL_SELECTOR not found, trying CELL_SELECTOR_OPEN");
|
||||
await contentFrame.waitForSelector(CELL_SELECTOR_OPEN, { timeout: 5000 }); // Adjust timeout as needed
|
||||
cell = await contentFrame.$(CELL_SELECTOR_OPEN);
|
||||
isCollapsed_main_before_function = false
|
||||
}
|
||||
|
||||
|
||||
let cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR)
|
||||
if (!cell_keuze) {
|
||||
cell_keuze = contentFrame.$(STPKT_KEUZE_CELL_SELECTOR_OPEN)
|
||||
}
|
||||
|
||||
if (!cell ) {
|
||||
throw new Error(
|
||||
|
@ -49,12 +66,15 @@ async function isStartPakketAvailable(page) {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
//object vars
|
||||
const isCollapsed_main = await isAriaExpandedFalse(cell);
|
||||
const isCollapsed_main = isCollapsed_main_before_function ? await isAriaExpandedFalse(cell) : isCollapsed_main_before_function;
|
||||
const isCollapsed_keuze = await getIsCollapsedKeuze(cell_keuze);
|
||||
const isCollapsed = isCollapsed_main && isCollapsed_keuze;
|
||||
const studName = await getStudName(contentFrame);
|
||||
const studId = await getStudId(contentFrame);
|
||||
const containsVZP = await hasVZP(cell)
|
||||
const containsVZP_keuze = await hasVZP(cell_keuze)
|
||||
|
||||
return {
|
||||
isCollapsed: isCollapsed,
|
||||
|
@ -62,6 +82,8 @@ async function isStartPakketAvailable(page) {
|
|||
isCollapsed_keuze: isCollapsed_keuze,
|
||||
studName: studName,
|
||||
studId: studId,
|
||||
containsVZP: containsVZP,
|
||||
containsVZP_keuze: containsVZP_keuze,
|
||||
// more properties here
|
||||
};
|
||||
}
|
||||
|
@ -73,7 +95,7 @@ async function isStartPakketAvailable(page) {
|
|||
* @returns {Promise<boolean>} True if the `aria-expanded` attribute is 'false', false otherwise.
|
||||
*/
|
||||
async function isAriaExpandedFalse(node) {
|
||||
if (!node) {
|
||||
if (isPromise(node)) {
|
||||
throw new Error("Node is not defined");
|
||||
}
|
||||
return await node.evaluate(
|
||||
|
@ -82,7 +104,7 @@ async function isAriaExpandedFalse(node) {
|
|||
}
|
||||
|
||||
async function getIsCollapsedKeuze(cell_keuze) {
|
||||
if (cell_keuze) {
|
||||
if (!isPromise(cell_keuze)) {
|
||||
return await isAriaExpandedFalse(cell_keuze);
|
||||
} else {
|
||||
return false;
|
||||
|
@ -105,4 +127,24 @@ async function getStudId(frame) {
|
|||
return await getNodeTextContent(cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the closest parent of the given node contains the 'VZP' string.
|
||||
*
|
||||
* @param {ElementHandle} node - The node to find the closest parent of.
|
||||
* @returns {Promise<boolean>} True if the closest parent contains 'VZP', false otherwise.
|
||||
*/
|
||||
async function hasVZP(node) {
|
||||
if (isPromise(node) ){
|
||||
return false;
|
||||
}
|
||||
return await node.evaluate((element) => {
|
||||
let parent = element.closest('table');
|
||||
if (parent) {
|
||||
return parent.textContent.includes('VZP')
|
||||
;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = isStartPakketAvailable;
|
||||
|
|
6
ispromise.js
Normal file
6
ispromise.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
function isPromise(obj) {
|
||||
return obj && typeof obj.then === 'function';
|
||||
}
|
||||
|
||||
module.exports = isPromise;
|
|
@ -9,7 +9,7 @@ const isStartPakketAvailable = require("./evaluateStartPakket");
|
|||
const fs = require("fs");
|
||||
const saveResultsToExcel = require("./saveResultsToExcel");
|
||||
const appendToExcel = require("./appendResultsToExcel");
|
||||
const wait = require("./wait");
|
||||
const wait = require("./wait");
|
||||
|
||||
async function iterateOverDashboardTable() {
|
||||
/*connection to local host */
|
||||
|
@ -18,8 +18,8 @@ async function iterateOverDashboardTable() {
|
|||
});
|
||||
|
||||
//array to store results for Excel export
|
||||
let results = []
|
||||
const filename = "DashboardResults.xlsx"
|
||||
let results = [];
|
||||
const filename = "DashboardResults.xlsx";
|
||||
|
||||
// Get all open pages (tabs)
|
||||
const pages = await browser.pages();
|
||||
|
@ -75,11 +75,23 @@ async function iterateOverDashboardTable() {
|
|||
const links = await iframe.$$(
|
||||
`${tableBodySelector} tr span[title="AA-rapport"] a`
|
||||
);
|
||||
// Get the parent row of the current link
|
||||
const parentRow = await links[i].evaluateHandle((link) =>
|
||||
link.closest("tr")
|
||||
);
|
||||
const rowContainsBeëindigd = await parentRow.evaluate((row) =>
|
||||
row.innerText.includes("Beëindigd")
|
||||
);
|
||||
|
||||
if (rowContainsBeëindigd) {
|
||||
console.log(`Skipping link ${i + 1} as the row contains 'Beëindigd'`);
|
||||
continue;
|
||||
}
|
||||
if ((i + 1) % 10 === 0) {
|
||||
console.log('Simulating break, waiting 10 seconds to stay under the radar :)')
|
||||
await wait(10000)
|
||||
|
||||
console.log(
|
||||
"Simulating break, waiting 10 seconds to stay under the radar :)"
|
||||
);
|
||||
await wait(10000);
|
||||
}
|
||||
|
||||
const [newPagePromise] = await Promise.all([
|
||||
|
@ -99,30 +111,32 @@ async function iterateOverDashboardTable() {
|
|||
const evaluationResult = await isStartPakketAvailable(newPage);
|
||||
|
||||
//Save results for Excel
|
||||
result = ({
|
||||
LinkNumber: i +1,
|
||||
StudentName: evaluationResult.studName || 'N/A',
|
||||
result = {
|
||||
LinkNumber: i + 1,
|
||||
StudentName: evaluationResult.studName || "N/A",
|
||||
StudentID: evaluationResult.studId || "N/A",
|
||||
IsCollapsed: evaluationResult.isCollapsed ? "Yes" : "No",
|
||||
IsCollapsedKeuze: evaluationResult.isCollapsed_keuze ? "Yes" : "No",
|
||||
IsCollapsedMain: evaluationResult.isCollapsed_main ? "Yes" : "No",
|
||||
})
|
||||
console.log(`Link ${i + 1 } processed successfully.`);
|
||||
|
||||
ContainsVZP: evaluationResult.containsVZP ? "Yes" : "No",
|
||||
ContainsVZPKeuze: evaluationResult.containsVZP_keuze ? "Yes" : "No"
|
||||
};
|
||||
console.log(`Link ${i + 1} processed successfully.`);
|
||||
} catch (error) {
|
||||
console.error(`Error processing link ${i + 1}:`, error.message);
|
||||
// Save error for Excel
|
||||
result = ({
|
||||
result = {
|
||||
LinkNumber: i + 1,
|
||||
StudentName: "Error",
|
||||
StudentID: "Error",
|
||||
IsCollapsed: "Error",
|
||||
IsCollapsedKeuze: "Error",
|
||||
IsCollapsedMain: "Error",
|
||||
ContainsVZP: "Error",
|
||||
ContainsVZPKeuze: "Error",
|
||||
ErrorStr: error.message,
|
||||
});
|
||||
}
|
||||
finally {
|
||||
};
|
||||
} finally {
|
||||
await newPage.close();
|
||||
}
|
||||
results.push(result);
|
||||
|
@ -132,8 +146,6 @@ async function iterateOverDashboardTable() {
|
|||
console.log("All links processed.");
|
||||
saveResultsToExcel(results, "DashboardResults.xlsx");
|
||||
console.log("Results saved successfully to DashboardResults.xlsx");
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = iterateOverDashboardTable();
|
||||
|
|
Loading…
Reference in New Issue
Block a user