-
Notifications
You must be signed in to change notification settings - Fork 0
/
SunnyPortal.py
executable file
·87 lines (69 loc) · 2.29 KB
/
SunnyPortal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python3
import os, time, dateutil.parser, datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# DEBUG
# import pdb; pdb.set_trace()
##
# CloudModuleTemplate
# Web page communications module
# Required class functions
# setCapabilities()
# setProfile()
##
class SunnyPortal:
def __init__(self):
self.urlLogin = "https://www.sunnyportal.com/Templates/Start.aspx?ReturnUrl=%2fTemplates%2fNoticePage.aspx"
self.urlLogout = ""
self.urlHeadDataPage = ""
self.urlDataPageExample = ""
self.ws = None
self.testing = True
self.lastElement = None
def doLogin(self,credentials):
return
def doLogout(self):
return
def getDataRecords(self):
dataRecs = {}
return dataRecs
# This always takes us to the main data page
##
def gotoDataPage(self):
if self.ws.driver == None:
return
return
def gotoLoginPage(self):
if self.ws.driver == None:
return
self.ws.driver.get(self.urlLogin)
self.waitFor("idClick","Login",10)
return
def setCapabilities(self,cap):
return cap
def setProfile(self,pro):
return pro
def setWebScraper(self,ws):
'''Pass web scraper class to this class'''
self.ws = ws
return
# Wrapper for explicit waits
# https://selenium-python.readthedocs.io/waits.html
##
def waitFor(self,elementType,elementValue,elementTimeout):
element = None
wait = WebDriverWait(self.ws.driver,elementTimeout)
try:
if elementType == "idClick":
element = wait.until(EC.element_to_be_clickable((By.ID,elementValue)))
if elementType == "class":
element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,elementValue)))
if elementType == "idNotPresent":
element = wait.until(EC.invisibility_of_element_located((By.ID,elementValue)))
if elementType == "xpath":
element = wait.until(EC.visibility_of_element_located((By.XPATH,elementValue)))
except:
pass
self.lastElement = element
return