Commit 05356a86 authored by bongo0594's avatar bongo0594
Browse files

Merge branch '5-more-resilient-moses' into 'master'

Resolve "More resilient student lookup in MOSES"

Closes #5

See merge request !3
parents 332a8bf9 cab03152
......@@ -31,7 +31,8 @@ class Person:
return ','.join(map(lambda x: shlex.quote(x), l))
def to_extended_str(self) -> str:
l = [self.name, self.surname, self.username, self.id, self.role, self.group, self.email, self.degree_program, self.degree]
l = [self.name, self.surname, self.username, self.id, self.role, self.group, self.email, self.degree_program,
self.degree]
return ','.join(map(lambda x: shlex.quote(x), l))
def fetch_details(self, session):
......@@ -41,7 +42,7 @@ class Person:
rsp = session.get(self.link)
soup = bs4.BeautifulSoup(rsp.content, 'html.parser')
basic = soup.find('div', id='j_idt105:j_idt106:personendaten')
basic = soup.find('div', id=lambda i: i is not None and ':personendaten' in i)
if basic:
# Label is dependent on the language
......@@ -56,7 +57,8 @@ class Person:
next(iter, None)
self.email = next(iter, None)
field = soup.find('div', id='j_idt105:j_idt249:j_idt251') # Field of study etc.
study = soup.find('div', id=lambda i: i is not None and ':studium' in i)
field = study.find(lambda t: t.name == 'div' and t.has_attr('class') and 'ui-datatable' in t['class'])
DEGREE_PROGRAM_LABEL_GER = 'Studiengang'
DEGREE_PROGRAM_LABEL_EN = 'Degree program'
......@@ -64,7 +66,7 @@ class Person:
DEGREE_LABEL_EN = 'Degree'
if field:
row = field.findNext('tr') # Skip header row
row = field.findNext('tr') # Skip header row
col_headers = list(map(lambda th: th.text, row.findAll('th')))
ix_program = None
......@@ -93,7 +95,6 @@ class Person:
self.degree = cols[ix_degree]
def search_people(session: requests.Session,
lastname='',
surname='',
......@@ -107,18 +108,39 @@ def search_people(session: requests.Session,
view_state = soup.find('input', attrs={'name': 'javax.faces.ViewState'})['value']
jfwid = soup.find('input', attrs={'name': 'javax.faces.ClientWindow'})['value']
form = soup.find(lambda tag: tag.name == 'form' and tag['id'].startswith('j_idt'))
lastname_id = form.find(lambda t: t.name == 'div' and
t.find('label').text in ['Nachname']).input['name'] # it's not translated
surname_id = form.find(lambda t: t.name == 'div' and
t.find('label').text in ['Vorname', 'First name']).input['name']
email_id = form.find(lambda t: t.name == 'div' and
t.find('label').text in ['E-Mail-Adresse']).input['name'] # not translated, either
username_id = form.find(lambda t: t.name == 'div' and
t.find('label').text in ['Benutzername', 'User name']).input['name']
student_id_id = \
form.find(lambda t: t.name == 'div' and
t.find('label').text in ['Matrikelnummer', 'Matriculation number']).input['name']
button_id = form.find(lambda t: t.name == 'a' and
t.has_attr('id') and t['id'].startswith(f'{form["id"]}:j_idt'))['id']
payload = {
"javax.faces.source": "j_idt105:j_idt122",
"javax.faces.source": button_id,
'javax.faces.partial.ajax': 'true',
'javax.faces.partial.execute': '@all',
'javax.faces.partial.render': 'j_idt105',
'j_idt105:j_idt122': 'j_idt105:j_idt122',
'j_idt105': 'j_idt105',
'j_idt105:j_idt107': lastname if lastname is not None else "",
'j_idt105:j_idt109': surname if surname is not None else "",
'j_idt105:j_idt113': email if email is not None else "",
'j_idt105:j_idt111': username if username is not None else "",
"j_idt105:j_idt115": student_id if student_id is not None else "",
'javax.faces.partial.render': form['id'],
button_id: button_id,
form['id']: form['id'],
lastname_id: lastname if lastname is not None else "",
surname_id: surname if surname is not None else "",
email_id: email if email is not None else "",
username_id: username if username is not None else "",
student_id_id: student_id if student_id is not None else "",
'javax.faces.ViewState': view_state,
'javax.faces.ClientWindow': jfwid
......
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