diff --git a/mccs-it/CSVFilterer.html b/mccs-it/CSVFilterer.html new file mode 100644 index 0000000..04c75cc --- /dev/null +++ b/mccs-it/CSVFilterer.html @@ -0,0 +1,25 @@ + + + + + + CSV Filterer + + + + +

CSV Filterer

+ + + +
+ + + +
+ + +

Status: Unknown

+ + + \ No newline at end of file diff --git a/mccs-it/CSVFilterer.js b/mccs-it/CSVFilterer.js new file mode 100644 index 0000000..802bd48 --- /dev/null +++ b/mccs-it/CSVFilterer.js @@ -0,0 +1,125 @@ +class UserData { + constructor(dataRow) { + this.userId = dataRow[0]; + this.uName = dataRow[1]; + this.fName = dataRow[3]; + this.sName = dataRow[5]; + } +} + +class EnrollmentData { + constructor(dataRow) { + this.orgUnitId = dataRow[0]; + this.userId = dataRow[1]; + this.roleName = dataRow[2]; + this.timestamp = dataRow[3]; + this.roleId = dataRow[5]; + this.fName = "N/A"; + this.sName = "N/A"; + this.uName = "N/A"; + } +} + +// Create empty Maps to store the filtered enrollment data and user info in +// These will be cross checked later to generate the list of all instructors +const users = new Map(); +const enrollments = new Map(); + +let states = { + enrollments: "Unfiltered", + users: "Unparsed" +} + +function filterEnrollments(document) { + let fileInput = document.getElementById('ueFileInput'); + let filterValue = "KV Instructor"; + document.getElementById('downloadLink') + if (!fileInput.files.length) { + alert('Please select a CSV file.'); + return; + } + + const file = fileInput.files[0]; + + Papa.parse(file, { + complete: function(results) { + // Iterate over the entire data set + results.data.forEach(row => { + // Create an EnrollmentData object with it: + const enrollmentData = new EnrollmentData(row); + // If the row contains the filter string and is not in the 'seen' Set + if (row.some(cell => cell.includes(filterValue)) && !enrollments.has(enrollmentData.userId)) { + // Add it to the data array + enrollments.set(enrollmentData.userId, enrollmentData); + } + }); + + states.enrollments = "Filtered"; + refreshStatus(document); + }, + error: function(error) { + console.error(error); + alert('An error occurred while processing the file.'); + } + }); +} + +const parseUsers = (usersFileInputs, document) => { + if (!usersFileInputs.files.length) { + alert('Please select a CSV file.'); + return; + } + + const usersFile = usersFileInputs.files[0]; + + Papa.parse(usersFile, { + complete: function(results) { + // Iterate over the entire data set + results.data.forEach(row => { + // Create an object with it: + const userData = new UserData(row); + // Add it to the data array + users.set(userData.userId, userData); + }); + states.users = "Parsed"; + refreshStatus(document); + generateList(document); + }, + error: function(error) { + console.error(error); + alert('An error occurred while processing the Users.csv file.'); + } + }); +} + +const generateList = (document) => { + const preCSV = [ + "UserId,Timestamp,FirstName,LastName,Username" + ]; + enrollments.forEach(e => { + // Get the associated user + const user = users.get(e.userId); + preCSV.push(`${user.userId},${e.timestamp}.${user.fName},${user.sName},${user.uName}`); + }); + + generateCSV(preCSV, document); +} + +const generateCSV = (input, document) => { + const downloadLink = document.getElementById("downloadLink"); + const csv = Papa.unparse(input); + + const blob = new Blob([csv], { type: 'text/csv' }); + const url = URL.createObjectURL(blob); + + downloadLink.href = url; + downloadLink.download = 'filtered.csv'; + downloadLink.style.display = 'block'; + downloadLink.textContent = 'Download Filtered CSV'; +} + +function refreshStatus(document) { + let statusSpan = document.getElementById('status') + let statusString = `Enrollments: ${states.enrollments} | Users: ${states.users}`; + statusSpan.innerHTML = statusString; +} \ No newline at end of file diff --git a/mccs-it/NewApplicant.py b/mccs-it/NewApplicant.py new file mode 100644 index 0000000..315ce81 --- /dev/null +++ b/mccs-it/NewApplicant.py @@ -0,0 +1,128 @@ +# coding=utf-8 +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.by import By +from selenium.webdriver.common.alert import Alert +import time +import getpass + +# Put +studentIds = [ + "5121951", + "5010522", + "5137363", + "5145175", + "5144503", + "5146582", + "5142212", + "5146605", + "5109465", + "5146602", + "5146608", + "5146598", + "5127204", + "5142694", + "5123415", + "5146588", + "5146589", + "5146600", + "5146581", + "5146506", + "5146609", + "5146607", + "5146601", + "5131148", + "5107200", + "5133891", + "5005257", + "5146590", + "5135862", + "5146599", + "5146586", + "5146552", + "5146308", + "5136688", + "5126696", +] + +class StudentInfo: + def __init__(self, name, id, auth_method, ad_ou): + self.name = name + self.id = id + self.auth_method = auth_method + self.ad_ou = ad_ou + +driver = webdriver.Firefox() + +def login(): + username = input("MyKV Username: ") + password = getpass.getpass(prompt="MyKV Password: ", stream=None) + driver.get("https://my.kvcc.me.edu/ics/") + time.sleep(1) + driver.find_element(By.ID, "userName").send_keys(username) + driver.find_element(By.ID, "password").send_keys(password) + driver.find_element(By.ID, "siteNavBar_welcomeBackBarLoggedOut_ButtonLogin").click() + time.sleep(1) + +def navToLookup(): + driver.get("https://my.kvcc.me.edu/ICS/IT_Admin/Help_Desk_Apps/") + time.sleep(1) + driver.find_element(By.ID, "pg0_V_lnkToMainView").click() + time.sleep(1) + + +def navToStudentInfo(id): + driver.get("https://my.kvcc.me.edu/jicspages/It_Utilities/Helpdesk/HelpDesk_Main.aspx?1=" + id + "&2=@@UserName&3=" + id) + +def getStudentInfo(): + stu_name = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[4]/td[1]").text + stu_id = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[4]/td[2]").text + # auth_text = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[5]/td[3]").text + auth_method = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[6]/td[1]").text + # ad_text = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[7]/td[2]").text + ad_ou = driver.find_element(By.XPATH, "//html/body/form/div/table/tbody/tr/td/span/table/tbody/tr[8]/td[3]").text + + info = StudentInfo(stu_name, stu_id, auth_method, ad_ou) + + combined = stu_name + " (" + stu_id + ")\nAD OU: "+ ad_ou + "\nAuthentication: " + auth_method + print(combined) + return info + +def resetPassword(info): + # TODO + driver.get("https://my.kvcc.me.edu/jicspages/It_Utilities/Helpdesk/HelpDesk_Main.aspx?1=" + info.id + "&2=@@UserName&3=" + info.id + "&4=3") + alert = Alert(driver) + print(alert.text) + alert.accept() + time.sleep(1) + driver.get("https://my.kvcc.me.edu/jicspages/It_Utilities/Helpdesk/HelpDesk_Main.aspx?1=" + info.id + "&2=@@UserName&3=" + info.id) + print("Password reset.") + +def createADAcct(info): + driver.get("https://my.kvcc.me.edu/jicspages/It_Utilities/Helpdesk/HelpDesk_Main.aspx?1=" + info.id + "&2=@@UserName&3=" + info.id + "&4=2") + alert = Alert(driver) + print(alert.text) + alert.accept() + time.sleep(1) + driver.get("https://my.kvcc.me.edu/jicspages/It_Utilities/Helpdesk/HelpDesk_Main.aspx?1=" + info.id + "&2=@@UserName&3=" + info.id) + +def checkStudentInfo(info): + if info.auth_method == "Portal Only": + print("No AD authentication, only resetting password.") + resetPassword(info) + elif info.auth_method == "Active Directory": + if info.ad_ou != "": + print("AD authentication set up, with an already existing account, only resetting password.") + resetPassword(info) + else: + print("AD authentication set up, without an AD account. Creating account then resetting password.") + resetPassword(info) + else: + print("Unable to determine authentication method. Please complete this manually.") + + +login() +for id in studentIds: + navToStudentInfo(id) + studentInfo = getStudentInfo() + checkStudentInfo(studentInfo) \ No newline at end of file diff --git a/mccs-it/UEFilterer.py b/mccs-it/UEFilterer.py new file mode 100644 index 0000000..600b470 --- /dev/null +++ b/mccs-it/UEFilterer.py @@ -0,0 +1,30 @@ +# Filters Brightspace's DataHub's UserEnrollments.csv file for a single college +# Install Python on Windows from Powershell by running `python` with no arguments +# pip install pandas + +import pandas as pd + +# Variables +college = 'KV' +ue_input_file = '.\\data\\UserEnrollments.csv' +ue_output_file = '.\\data\\UEFiltered' + college + '.csv' +ue_field_name = 'RoleName' +ue_filter_value = college + ' Instructor' + +users_input_file = '.\\data\\Users.csv' +users_output_file = '.\\data\\UsersFiltered' + college + '.csv' +users_field_name = 'UserName' +users_filter_value = "KV_" + +def filter_csv(input_file, output_file, field_name, filter_value): + # Read the CSV file + df = pd.read_csv(input_file) + + # Filter the DataFrame based on the field value + filtered_df = df[df[field_name].str.contains(filter_value, na=False)] + + # Export the filtered DataFrame to a new CSV file + filtered_df.to_csv(output_file, index=False) + +filter_csv(ue_input_file, ue_output_file, ue_field_name, ue_filter_value) +filter_csv(users_input_file, users_output_file, users_field_name, users_filter_value) \ No newline at end of file