custom-scripts/mccs-it/NewApplicant.py

126 lines
4.1 KiB
Python
Raw Normal View History

2024-08-13 13:48:52 +00:00
# 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 = [
2024-09-04 20:35:51 +00:00
"5010151",
"5146775",
"5119928",
"5103282",
"5136913",
"5146786",
"5146756",
"5146746",
"5117953",
"5146715",
"5120182",
"5146758",
"5143217",
"5134303",
"5125039",
"5146520",
"5128953",
"5146785",
"5138867",
"5146759",
"5129320",
"5115236",
"5146757",
"5146783",
"5136183",
"5146784",
"5146782",
"5120562",
"5132114",
"5122637",
"5146787",
"5108584",
"5137846"
2024-08-13 13:48:52 +00:00
]
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)