Commit fb86b3ec authored by aal's avatar aal
Browse files

teil 2 von vier(aber broken)

parent 695bf675
......@@ -19,20 +19,21 @@ 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(argv=None):
user, password, path, ignore, blacklist = None, None, None, None, None
allsemesters = False
def main():
parser = initParser()
args = parser.parse_args()
##TODO: parse em for real
cookie = sso_login('user', 'password')
parse_args(user, password, path, allsemesters, ignore, blacklist)
print(user)
print(password)
cookie = sso_login(user, password)
with requests.session() as session:
session.cookies = requests.utils.cookiejar_from_dict(cookie)
scrape(session)
def initParser():
def parse_args(user, password, path, allsemesters, ignore, blacklist):
try:
import keyring
except ImportError:
......@@ -41,25 +42,66 @@ def initParser():
usekeyring = True
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--path', help='Pfad für lokalen Datei
baum')
parser.add_argument('-p', '--path', help='Pfad für lokalen Dateibaum')
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
parser.add_argument('-pw', '--password', help='Stud.IP Passwort')
parser.add_argument('-b', '--blacklist', help='Blacklist für Veranstaltungen, mehrmals angeben für mehrere Veranstaltungen', action='append')
parser.add_argument('-i', '--ignore', help='Blacklist für Dateinamen 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 ohne Angabe in $XDG_CONFIG_HOME/studsauger/config.json oder $HOME/.config/studsauger/config.json gesucht')
args = parser.parse_args()
configpath = None
if args.config:
if os.path.isfile(config):
configpath = args.config
else:
print('Konfigurationsdatei "' + args.config + '" existiert nicht.')
exit(1)
elif 'XDG_CONFIG_HOME' in os.environ:
if os.path.isfile(os.environ['XDG_CONFIG_HOME'] + '/studsauger/config.json'):
configpath = os.environ['XDG_CONFIG_HOME'] + '/studsauger/config.json'
elif 'HOME' in os.environ:
if os.path.isfile(os.environ['HOME'] + '/.config/studsauger/config.json'):
configpath = os.environ['HOME'] + '/.config/studsauger/config.json'
if configpath:
with open(configpath, 'r') as stream:
config = json.load(stream)
else:
config = {}
if args.path:
path = args.path
elif 'path' in config:
path = config['path']
else:
print('Kein Pfad angegeben!')
parser.print_help()
exit(1)
if args.user:
user = args.user
elif 'user' in config:
user = config['user']
else:
print('Kein Benutzer angegeben!')
parser.print_help()
exit(1)
if usekeyring:
keyringpw = keyring.get_password('studsauger', user)
if keyringpw:
password = keyringpw
if args.password or 'password' in config:
print('Passwort für Benutzer "' + user + '" ist im Keyring und darf nicht angegeben werden!')
exit(1)
elif args.password:
password = args.password
#TODO: return session in case i wanna implement oauth for a month? (and also because it seems prettier)
# 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,7 +119,7 @@ def sso_login(username, password):
def scrape(session):
allsemesters = False
ignore = None
ignore = ''
path = './Test'
blacklist = {}
###
......@@ -113,9 +155,8 @@ def scrape(session):
#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
if re.match(ignore, document['name']):
continue
date = ''
if document['file_id'] in database:
if database[document['file_id']] == document['chdate']:
......
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