Commit bff3f039 authored by Gabriel Dengler's avatar Gabriel Dengler
Browse files

👽 Adding explicit switch to user mode for persons who have also a...

👽 Adding explicit switch to user mode for persons who have also a different role, e.g., as teaching staff
parent 60c75a0b
......@@ -15,6 +15,8 @@ headers = {
+ '(KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
}
main_page = 'https://www.campo.fau.de/qisserver/pages/cs/sys/portal/hisinoneStartPage.faces'
url_exams_page = 'https://www.campo.fau.de/qisserver/pages/sul/examAssessment/personExamsReadonly.xhtml?' \
'_flowId=examsOverviewForPerson-flow&_flowExecutionKey=e1s1'
......@@ -33,7 +35,7 @@ class Connection:
colorama_init(autoreset=True)
def __enter__(self):
self.s = requests.session()
self.s = requests.Session()
with ExitStack() as stack:
stack.enter_context(self.s)
self._stack = stack.pop_all()
......@@ -65,8 +67,8 @@ class Connection:
return r
def __post(self, url, data):
print_info(f"get {urlparse(url).netloc}")
r = self.s.post(url, data=data, headers=headers, timeout=5)
print_info(f"post {urlparse(url).netloc}")
r = self.s.post(url, data=data, headers=headers, timeout=10)
r.raise_for_status()
return r
......@@ -80,6 +82,7 @@ class Connection:
if not success:
return False
self.__switch_to_student()
self.__expand_rows()
return True
......@@ -119,6 +122,32 @@ class Connection:
return True
def __switch_to_student(self):
# Get authenticity token
raw_site = self.__get(main_page)
dom = fromstring(raw_site.text)
self.authenticity_token = dom.xpath('//input[@name=\'authenticity_token\']/@value')[0]
self.view_state = dom.xpath('//input[@name=\'javax.faces.ViewState\']/@value')[0]
# Switch user to student mode
data = {
'authenticity_token': self.authenticity_token,
'navigationPosition': 'link_homepage',
'widgetRender:11:roleSwitcherForm:roles_input': '475395', # Student id
'widgetRender:11:roleSwitcherForm:roles_focus': '',
'widgetRender:11:roleSwitcherForm:roles_filter': '',
'widgetRender:11:roleSwitcherForm_SUBMIT': '1',
'autoScroll': '0,0',
'refreshButtonClickedId': '',
'DISABLE_VALIDATION': 'true',
'javax.faces.ViewState': self.view_state,
'widgetRender:11:roleSwitcherForm:_idcl': 'widgetRender:11:roleSwitcherForm:j_id_4d_3_b_r_2_1_3_1_1_5_1_1',
'activePageElementId': 'widgetRender:11:roleSwitcherForm:j_id_4d_3_b_r_2_1_3_1_1_5_1_1'
}
self.__post(main_page, data)
def __expand_rows(self):
# Get authenticity token
raw_site = self.__get(url_exams_page)
......@@ -151,7 +180,7 @@ class Connection:
self.__post(url_exams_page, data)
def __read_grades(self):
def __read_grades(self):
# Open grades page
raw_site = self.__get(url_exams_page)
dom = fromstring(raw_site.text)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment