Commit cec32ad3 authored by Kiste's avatar Kiste
Browse files

Implement downloading all semesters

parent 24922c81
......@@ -12,40 +12,43 @@ def mkdir(directory):
BASEURL = 'https://studip.uni-hannover.de/plugins.php/restipplugin/api'
def logik(path, user, password, blacklist, allsemesters):
mkdir(path)
s = requests.Session()
s.auth = (user, password)
jsemester = s.get(BASEURL + '/courses/semester')
if allsemesters:
for semester in jsemester.json()['semesters']:
fetchsemester(path, s, blacklist, semester)
holsemester(path + '/' + semester['title'].replace('/', ''), s, blacklist, semester)
else:
fetchsemester(path, s, blacklist, jsemester.json()['semesters'][-1])
holsemester(path, s, blacklist, jsemester.json()['semesters'][-1])
def holsemester(path, s, blacklist, cursemester):
mkdir(path)
jcourses = s.get(BASEURL + '/courses/semester/' + cursemester['semester_id'])
def fetchsemester(path, s, blacklist, cursemester):
semester_id = cursemester['semester_id']
semester_title = cursemester['title']
jcourses = s.get(BASEURL + '/courses/semester/' + semester_id)
for course in jcourses.json()['courses']:
course_id = course['course_id']
course_title = course['title']
if course_title in blacklist:
if course['title'] in blacklist:
continue
mkdir(path + '/' + course_title)
jfolder = s.get(BASEURL + '/documents/' + course_id + '/folder')
mkdir(path + '/' + course['title'])
jfolder = s.get(BASEURL + '/documents/' + course['course_id'] + '/folder')
for folder in jfolder.json()['folders']:
folder_id = folder['folder_id']
folder_name = folder['name']
jfiles = s.get(BASEURL + '/documents/' + course_id + '/folder/' + folder_id)
for file in jfiles.json()['documents']:
document_id = file['document_id']
filename = file['filename']
f = path + '/' + course_title + '/' + filename
if not os.path.isfile(f):
fdl = s.get(BASEURL + '/documents/' + document_id + '/download', stream=True)
if fdl.status_code == 200:
with open(f, 'wb') as file:
fdl.raw.decode_content = True
shutil.copyfileobj(fdl.raw, file)
holordner(path, s, course, folder)
def holordner(path, s, course, folder):
jfiles = s.get(BASEURL + '/documents/' + course['course_id'] + '/folder/' + folder['folder_id'])
for subfolder in jfiles.json()['folders']:
holordner(path, s, course,subfolder)
for file in jfiles.json()['documents']:
f = path + '/' + course['title'] + '/' + file['filename']
if not os.path.isfile(f):
fdl = s.get(BASEURL + '/documents/' + file['document_id'] + '/download', stream=True)
if fdl.status_code == 200:
with open(f, 'wb') as file:
fdl.raw.decode_content = True
shutil.copyfileobj(fdl.raw, file)
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