add mccs scripts
This commit is contained in:
parent
963dbae8d8
commit
886eb58842
25
mccs-it/CSVFilterer.html
Normal file
25
mccs-it/CSVFilterer.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CSV Filterer</title>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
|
||||
<script src="./CSVFilterer.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CSV Filterer</h1>
|
||||
<label for="ueFileInput">UserEnrollments.csv:</label>
|
||||
<input type="file" id="ueFileInput" accept=".csv">
|
||||
<button onclick="filterEnrollments(document)">Filter Enrollments</button>
|
||||
<br />
|
||||
<label for="usersFileInput">Users.csv:</label>
|
||||
<input type="file" id="usersFileInput" accept=".csv">
|
||||
<button onclick="parseUsers(document.getElementById('usersFileInput'), document)">Parse Users</button>
|
||||
<br />
|
||||
|
||||
<button onclick="refreshStatus(document)">Refresh Status</button>
|
||||
<p>Status: <span id="status">Unknown</span></p>
|
||||
<a id="downloadLink" style="display:none;">Download Filtered CSV</a>
|
||||
</body>
|
||||
</html>
|
125
mccs-it/CSVFilterer.js
Normal file
125
mccs-it/CSVFilterer.js
Normal file
@ -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;
|
||||
}
|
128
mccs-it/NewApplicant.py
Normal file
128
mccs-it/NewApplicant.py
Normal file
@ -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)
|
30
mccs-it/UEFilterer.py
Normal file
30
mccs-it/UEFilterer.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user