Skip to content

Commit

Permalink
Initial WolvTerm commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sidpagariya committed Dec 17, 2018
1 parent 57b40a9 commit 3200c2e
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 0 deletions.
Binary file added WolvTerm/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions WolvTerm/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/local/bin/python3"
}
Binary file added WolvTerm/__pycache__/cookies.cpython-37.pyc
Binary file not shown.
Binary file added WolvTerm/__pycache__/helpers.cpython-37.pyc
Binary file not shown.
Binary file added WolvTerm/__pycache__/pages.cpython-37.pyc
Binary file not shown.
Binary file added WolvTerm/__pycache__/webdriver.cpython-37.pyc
Binary file not shown.
50 changes: 50 additions & 0 deletions WolvTerm/browse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from webdriver import driver
from cookies import readCookies, writeCookies
from helpers import handleLogin, quitSess
from pages import Home, Student, StudentCenter, EmployeeSelfService
import time, os, sys

def main_menu():
while True:
#os.system('cls' if sys.platform == 'win32' else 'clear')
print ("Welcome to WolvTerm 0.0.1!\n")
print ("Please choose the menu you want to start:")
print ("1. Home")
print ("2. Student")
print ("3. Employee Self-Service")
print ("\n0. Quit")
choice = input(">> ")
exec_menu(choice)
return

def exec_menu(choice):
#os.system('cls' if sys.platform == 'win32' else 'clear')
ch = choice.lower()
if ch == '':
menu_actions['main_menu']()
else:
try:
menu_actions[ch]()
except KeyError:
print ("Invalid selection, please try again.\n")
menu_actions['main_menu']()
return

def exitSess():
quitSess()
exit()

menu_actions = {
'main_menu': main_menu,
'1': Home,
'2': Student,
'3': EmployeeSelfService,
'0': exitSess
}

if __name__ == "__main__":
Home()
main_menu()
# Home()
#StudentCenter()
# quitSess()
42 changes: 42 additions & 0 deletions WolvTerm/cookies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pickle, getpass
from webdriver import driver
def readCookies():
if driver.title == '' or driver.title == None:
print("Title is not valid!")
from pages import Home
Home()

try:
with open('cookies.pkl', 'rb') as j:
cookies = pickle.load(j)
for cookie in cookies:
driver.add_cookie(cookie)
print("Using cookies")
except Exception as e:
print(str(e))
#print("Continuing without cookies")
from pages import Student
from helpers import enterLogin, navTo, enterTextId, pressEnterId, waitId
print(driver.title)
print("Getting cookies now...")
navTo('https://csprod.dsc.umich.edu/services/student')
print(driver.title)

if 'Weblogin' in driver.title:
try:
usr = getpass.getpass('Username [Hidden]: ')
password = getpass.getpass('Password [Hidden]: ')
enterTextId('login', usr)
enterTextId('password', password)
pressEnterId('password')
except Exception as e:
print("Oops, something went wrong...")
print(str(e))
waitId('PT_NAVBAR')



def writeCookies():
#pickle.dump(driver.get_cookies(), open("cookies.pkl", "wb"))
with open('cookies.pkl', 'wb') as j_out:
pickle.dump(driver.get_cookies(), j_out)
65 changes: 65 additions & 0 deletions WolvTerm/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from webdriver import driver
from cookies import readCookies, writeCookies
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import getpass

def enterTextId(id, text):
elem = driver.find_element_by_id(id)
elem.clear()
elem.send_keys(text)

def pressEnterId(id):
elem = driver.find_element_by_id(id)
elem.send_keys(Keys.RETURN)

def enterLogin():
if 'Weblogin' in driver.title:
try:
usr = getpass.getpass('Username [Hidden]: ')
password = getpass.getpass('Password [Hidden]: ')
enterTextId('login', usr)
enterTextId('password', password)
pressEnterId('password')
except Exception as e:
print("Oops, something went wrong...")
print(str(e))
waitId('PT_NAVBAR')

def waitId(id):
wait = WebDriverWait(driver, 60)
try:
wait.until(EC.presence_of_element_located((By.ID, id)))
finally:
driver.quit()

def waitTitle(str):
wait = WebDriverWait(driver, 60)
try:
wait.until(not EC.title_is(str))
finally:
driver.quit()

def navTo(url):
driver.get(url)

def close():
driver.close()

def quitSess():
writeCookies()
driver.close()
driver.quit()

def handleLogin(func, args=None):
if 'Weblogin' in driver.title:
enterLogin()
waitId('PT_NAVBAR')
#waitTitle('WebLogin')
if args:
func(args)
else:
func()

15 changes: 15 additions & 0 deletions WolvTerm/pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from webdriver import driver
from helpers import navTo, handleLogin

def Home():
navTo('https://wolverineaccess.umich.edu')

def Student():
navTo('https://csprod.dsc.umich.edu/services/student')

def StudentCenter():
Student()
driver.execute_script("LaunchURL(this,'https://csprod.dsc.umich.edu/psp/csprodnonop_newwin/EMPLOYEE/SA/c/SA_LEARNER_SERVICES.SSS_STUDENT_CENTER.GBL',0,'bGrouplet@1;','')")

def EmployeeSelfService():
navTo('https://hcmprod.dsc.umich.edu/services/employee')
Empty file added WolvTerm/run.py
Empty file.
19 changes: 19 additions & 0 deletions WolvTerm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from cookies import readCookies, writeCookies
from webdriver import driver
from helpers import handleLogin, quitSess
from pages import Home, Student, StudentCenter, EmployeeSelfService
from helpers import navTo

#cookies = pickle.load(open("cookies.pkl", "rb"))
readCookies()
# Home()
# print(driver.title)
# # Student()
# navTo('https://csprod.dsc.umich.edu/services/student')
# print(driver.title)
# # StudentCenter()
# StudentCenter()
# print(driver.title)
# #assert "No results found." not in driver.page_source
#quitSess()
driver.quit()
16 changes: 16 additions & 0 deletions WolvTerm/webdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from selenium import webdriver
from sys import platform as _platform
import platform

driver = ""
opts = webdriver.ChromeOptions()
opts.add_argument('headless')
opts.add_argument('remote-debugging-port=9222')
if _platform.startswith("linux"):
driver = webdriver.Chrome(executable_path="webdrivers/chromedriver-linux", options=opts)
elif _platform == "darwin":
driver = webdriver.Chrome(executable_path="webdrivers/chromedriver-mac", options=opts)
elif _platform == "win32" or _platform == "win64":
driver = webdriver.Chrome(executable_path="webdrivers/chromedriver-windows.exe", options=opts)

# driver.close()
Binary file added WolvTerm/webdrivers/.DS_Store
Binary file not shown.
Binary file added WolvTerm/webdrivers/chromedriver-linux
Binary file not shown.
Binary file added WolvTerm/webdrivers/chromedriver-mac
Binary file not shown.
Binary file added WolvTerm/webdrivers/chromedriver-windows.exe
Binary file not shown.

0 comments on commit 3200c2e

Please sign in to comment.