Refactor and document code; add new files
Refactored `script.py` by adding detailed docstrings and organizing functions. Created `.idea` configuration files and `gotodashboard.js` for `sisa_crawl` project. Added `readme.md` files with usage instructions and context for multiple scripts, and set up `package.json` for `sisa_crawl` dependencies.
This commit is contained in:
commit
921cfa389c
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
12
.idea/sisa_crawl.iml
Normal file
12
.idea/sisa_crawl.iml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
31
gotodashboard.js
Normal file
31
gotodashboard.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
const {runId, dasbhoardInschrijvingenURL} = require('./vars.js');
|
||||||
|
|
||||||
|
async function runGoToDashboard(page) {
|
||||||
|
try {
|
||||||
|
await page.waitForSelector('#PS_SCP_REG_USER_F_S\\$19'); // Escape `$` in the ID
|
||||||
|
|
||||||
|
// Click the element
|
||||||
|
await page.click('#PS_SCP_REG_USER_F_S\\$19');
|
||||||
|
try {
|
||||||
|
await page.goto(dasbhoardInschrijvingenURL);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("The page could not be reached.", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await page.waitForSelector('#PRCSRUNCNTL_RUN_CNTL_ID')
|
||||||
|
await page.type("#PRCSRUNCNTL_RUN_CNTL_ID[type='text']", runId)
|
||||||
|
await page.keyboard.press("Enter");
|
||||||
|
|
||||||
|
await page.waitForSelector('#PTS_CFG_CL_RSLT_NUI_SRCH1\\$12\\$\\$0')
|
||||||
|
await page.click('#PTS_CFG_CL_RSLT_NUI_SRCH1\\$12\\$\\$0')
|
||||||
|
|
||||||
|
|
||||||
|
return page;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("An error occurred:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = runGoToDashboard;
|
16
index.js
Normal file
16
index.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
const runLoginScript = require('./login');
|
||||||
|
const launchBrowser = require('./launchbrowser');
|
||||||
|
const runGoToDashboard = require('./gotodashboard');
|
||||||
|
const handleDashboardForm = require('./handleDashboardForm');
|
||||||
|
const inquirer = require('inquirer');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const browser = await launchBrowser();
|
||||||
|
const page1 = await runLoginScript(browser);
|
||||||
|
const page2 = await runGoToDashboard(page1);
|
||||||
|
const page3 = await handleDashboardForm(page2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
9
launchbrowser.js
Normal file
9
launchbrowser.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const puppeteer = require("puppeteer");
|
||||||
|
|
||||||
|
async function launchBrowser() {
|
||||||
|
return puppeteer.launch({
|
||||||
|
executablePath: process.env.CHROMIUM_PATH || 'C:\\Users\\bdaneels\\Documents\\chromium\\chrome-win\\chrome.exe',
|
||||||
|
headless: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
module.exports = launchBrowser;
|
42
login.js
Normal file
42
login.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
const { email, password, webpage } = require("./vars.js");
|
||||||
|
|
||||||
|
async function runLoginScript(browser) {
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
// Navigate to the login page
|
||||||
|
await page.goto(webpage);
|
||||||
|
|
||||||
|
// Wait for 5 seconds
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
|
||||||
|
// Enter the email
|
||||||
|
await page.type(".form-control[type='email']", email);
|
||||||
|
console.log("email entered");
|
||||||
|
// Wait for 5 seconds
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
|
||||||
|
//press enter keyboard
|
||||||
|
await page.keyboard.press("Enter");
|
||||||
|
// Wait for 5 seconds
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
|
||||||
|
// Enter the password
|
||||||
|
await page.type(".form-control[type='password']", password);
|
||||||
|
console.log("password entered");
|
||||||
|
await page.keyboard.press("Enter");
|
||||||
|
// Wait for 5 seconds
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
|
||||||
|
// wait for the user to input the google auth code
|
||||||
|
console.log("waiting for auth code");
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 15000));
|
||||||
|
return page
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("An error occurred:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = runLoginScript;
|
14
package.json
Normal file
14
package.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "sisa_crawl",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"inquirer": "^12.1.0",
|
||||||
|
"puppeteer": "^23.7.0"
|
||||||
|
}
|
||||||
|
}
|
26
vars.js
Normal file
26
vars.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
/* Top Level Vars*/
|
||||||
|
const email = 'bdaneels@ad.ua.ac.be'
|
||||||
|
const password = 'Heideggershut18891'
|
||||||
|
const webpage = 'https://sisaweb.uantwerpen.be'
|
||||||
|
const runId = 'bd'
|
||||||
|
const dasbhoardInschrijvingenURL = 'https://app.sisaweb.uantwerpen.be/psc/csprd_3/EMPLOYEE/SA/c/QQ_INSCHRIJVINGEN.QQ_OVERZ_ING_STDL.GBL?NavColl=true'
|
||||||
|
|
||||||
|
|
||||||
|
/* Dashboard Form Vars*/
|
||||||
|
|
||||||
|
const career = 'BACA'
|
||||||
|
const program = 'B0011'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
webpage,
|
||||||
|
runId,
|
||||||
|
dasbhoardInschrijvingenURL,
|
||||||
|
career,
|
||||||
|
program
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user