From 921cfa389c4d4fd9df655d8f6b36041381164d13 Mon Sep 17 00:00:00 2001 From: bdaneels Date: Mon, 18 Nov 2024 14:03:23 +0100 Subject: [PATCH] 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. --- .idea/.gitignore | 5 +++++ .idea/sisa_crawl.iml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ gotodashboard.js | 31 +++++++++++++++++++++++++++++++ index.js | 16 ++++++++++++++++ launchbrowser.js | 9 +++++++++ login.js | 42 ++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++++++++ vars.js | 26 ++++++++++++++++++++++++++ 9 files changed, 161 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/sisa_crawl.iml create mode 100644 .idea/vcs.xml create mode 100644 gotodashboard.js create mode 100644 index.js create mode 100644 launchbrowser.js create mode 100644 login.js create mode 100644 package.json create mode 100644 vars.js diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/sisa_crawl.iml b/.idea/sisa_crawl.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/sisa_crawl.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/gotodashboard.js b/gotodashboard.js new file mode 100644 index 0000000..bc1ed3a --- /dev/null +++ b/gotodashboard.js @@ -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; \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..69ad72e --- /dev/null +++ b/index.js @@ -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); + + + +})(); + diff --git a/launchbrowser.js b/launchbrowser.js new file mode 100644 index 0000000..cdaabbe --- /dev/null +++ b/launchbrowser.js @@ -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; \ No newline at end of file diff --git a/login.js b/login.js new file mode 100644 index 0000000..de1cd5f --- /dev/null +++ b/login.js @@ -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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..6265678 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/vars.js b/vars.js new file mode 100644 index 0000000..acee515 --- /dev/null +++ b/vars.js @@ -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 +}; \ No newline at end of file