custom-scripts/mccs-it/NewApplicant.py

128 lines
4.2 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 = [
"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)