diff options
Diffstat (limited to 'moodler.py')
| -rwxr-xr-x | moodler.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/moodler.py b/moodler.py new file mode 100755 index 0000000..5ff9d82 --- /dev/null +++ b/moodler.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +#-*- coding:utf-8 -*- + +import http.cookiejar +import urllib.request +import urllib.parse +import config +from bs4 import BeautifulSoup + +cookiejar = http.cookiejar.CookieJar() + +opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookiejar)) +urllib.request.install_opener(opener) + +data = urllib.parse.urlencode({'username': config.username, 'password': config.password}) +data = data.encode('utf-8') + +request = urllib.request.Request(config.moodleurl + 'login/index.php') + +# Login +f = urllib.request.urlopen(request, data) + +# Scrapen starten +f = urllib.request.urlopen(config.moodleurl + 'user/index.php?perpage=999999&mode=1&id=' + str(config.courseid)) +soup = BeautifulSoup(f.read()) + +# iterieren und speichern +users = dict() +for cell in soup.find_all('td', class_='content'): + thisuser = cell.find_all('div', class_='username') + if thisuser: + thisuser = thisuser[0] + if thisuser: + thisuser = thisuser.string + + thismail = cell.find_all('a') + if thismail: + thismail = thismail[0] + if thismail: + thismail = thismail.string + + users[thisuser] = thismail + +f = open('data/users.txt', mode='w', encoding='utf-8') +f.write(str(users)) +f.close() |
