Commit 695bf675 authored by aal's avatar aal
Browse files

argparse teil I der quadrupologie

parent 1fb9840a
......@@ -95,4 +95,4 @@ def main(args=None):
mkdir(path)
sso_login(user, password)
main()
\ No newline at end of file
main()
......@@ -6,7 +6,7 @@ terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
"""
import argparse
import json
import os
import re
......@@ -19,14 +19,47 @@ import lxml.html
BASEURL = 'https://studip.uni-hannover.de/api.php'
LOGIN_URL = "https://studip.uni-hannover.de/Shibboleth.sso/Login?target=https%3A%2F%2Fstudip.uni-hannover.de%2Findex.php%3Fagain%3Dyes%26sso%3Dshib"
SAML_URL = "https://studip.uni-hannover.de/Shibboleth.sso/SAML2/POST"
configpath = None
def main():
parser = initParser()
args = parser.parse_args()
##TODO: parse em for real
cookie = sso_login('user', 'password')
with requests.session() as session:
session.cookies = requests.utils.cookiejar_from_dict(cookie)
scrape(session)
def initParser():
try:
import keyring
except ImportError:
usekeyring = False
else:
usekeyring = True
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--path', help='Pfad für lokalen Datei
baum')
parser.add_argument('-u', '--user', help='Stud.IP Benutzername')
parser.add_argument('-pw', '--password', help='Stud.IP Passwort'
)
parser.add_argument('-b', '--blacklist', help='Blacklist für Ver
anstaltungen, mehrmals angeben für mehrere Veranstaltungen', action=
'append')
parser.add_argument('-i', '--ignore', help='Blacklist für Datein
amen als regex')
parser.add_argument('-a', '--allsemesters', help='Alle Semester
statt nur dem aktuellen', action="store_true")
parser.add_argument('-c', '--config',
help='JSON-Konfigurationsdatei, wird ohn
e Angabe in $XDG_CONFIG_HOME/studsauger/config.json oder $HOME/.conf
ig/studsauger/config.json gesucht')
return parser
# beatiful POS that returns the Seminar_Session Cookie necessary for accessing the API
def sso_login(username, password):
# Start session and get login form.
......@@ -77,8 +110,10 @@ def scrape(session):
mkdir(path + '/' + course['title'].replace('/', '_'))
json_folders = session.get(BASEURL + '/course/' + course['course_id'] + '/top_folder', params='limit=1000').json()
for folder in json_folders['subfolders']:
#TODO: go to subfolders as well
json_files = session.get(BASEURL + '/folder/' + folder['id']).json()
for document in json_files['file_refs']:
#TODO: make this work again
#if re.match(ignore, document['name']):
# continue
date = ''
......
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