Commit a5fe9402 authored by Kiste's avatar Kiste
Browse files

User requests session

parent 2c4ac50c
......@@ -55,11 +55,13 @@ else:
blacklist = {}
mkdir(config['path'])
jsemester = requests.get(BASEURL + '/courses/semester', auth=(config['user'], config['password']))
s = requests.Session()
s.auth = (user, password)
jsemester = s.get(BASEURL + '/courses/semester')
semester_id = jsemester.json()['semesters'][-1]['semester_id']
semester_title = jsemester.json()['semesters'][-1]['title']
print('Lade Semester: ' + semester_title)
jcourses = requests.get(BASEURL + '/courses/semester/' + semester_id, auth=(config['user'], config['password']))
jcourses = s.get(BASEURL + '/courses/semester/' + semester_id)
for course in jcourses.json()['courses']:
course_id = course['course_id']
course_title = course['title']
......@@ -67,17 +69,17 @@ for course in jcourses.json()['courses']:
continue
print('Lade Kurs: ' + course_title)
mkdir(config['path'] + '/' + course_title)
jfolder = requests.get(BASEURL + '/documents/' + course_id + '/folder', auth=(config['user'], config['password']))
jfolder = s.get(BASEURL + '/documents/' + course_id + '/folder')
for folder in jfolder.json()['folders']:
folder_id = folder['folder_id']
jfiles = requests.get(BASEURL + '/documents/' + course_id + '/folder/' + folder_id, auth=(config['user'], config['password']))
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 = config['path'] + '/' + course_title + '/' + filename
if not os.path.isfile(f):
print('Lade ' + filename)
fdl = requests.get(BASEURL + '/documents/' + document_id + '/download', auth=(config['user'], config['password']), stream=True)
fdl = s.get(BASEURL + '/documents/' + document_id + '/download', stream=True)
if fdl.status_code == 200:
with open(f, 'wb') as file:
print('Writing ' + f)
......
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