From anonymous, 1 Week ago, written in Python.
Embed
  1. import requests
  2. import bs4
  3. import sys
  4.  
  5. user = 'CHANGE_ME'
  6. password = 'CHANGE_ME'
  7.  
  8. def progress(text=''):
  9.     if '--cron' not in sys.argv:
  10.         print(text)
  11.  
  12. progress("Getting login page...")
  13. sess = requests.Session()
  14. res = sess.get('https://adfs.hsr.ch/adfs/ls/?wa=wsignin1.0&wtrealm=https%3A%2F%2Funterricht.hsr.ch%2F')
  15. res.raise_for_status()
  16. soup = bs4.BeautifulSoup(res.text, 'html.parser')
  17. link = soup.find(id='loginForm')['action']
  18.  
  19. progress("Logging in [1/2]...")
  20. res = sess.post('https://adfs.hsr.ch' + link, data={'UserName': 'hsr.ch\\' + user, 'Password': password, 'AuthMethod': 'FormsAuthentication'})
  21. res.raise_for_status()
  22. soup = bs4.BeautifulSoup(res.text, 'html.parser')
  23. form = soup.find('form')
  24.  
  25. progress("Logging in [2/2]...")
  26. data = {}
  27. for inp in form.find_all('input'):
  28.     if inp['type'] == 'submit': continue
  29.     data[inp['name']] = inp['value']
  30.  
  31. res = sess.post(form['action'], data=data)
  32. res.raise_for_status()
  33.  
  34. progress("Switching role...")
  35. res = sess.post('https://unterricht.hsr.ch/Application/ReloginAs', data={'loginName': user, 'rollenArt': 'Student'})
  36. res.raise_for_status()
  37.  
  38. progress("Getting report...")
  39. progress()
  40.  
  41. report = []
  42. res = sess.get('https://unterricht.hsr.ch/MeinStudium/Studium/SemesterReport')
  43. res.raise_for_status()
  44. soup = bs4.BeautifulSoup(res.text, 'html.parser')
  45. for tr in soup.find('tbody').find_all('tr'):
  46.     tds = tr.find_all('td')
  47.     name = tds[1].text
  48.     grade = tds[2].text
  49.     text = '{}: {}'.format(name, grade)
  50.     progress(text)
  51.     if grade != '***':
  52.         report.append(grade)
  53.  
  54. for line in report:
  55.     print(line)
  56.