Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
aal
studsoiger
Commits
cec32ad3
Commit
cec32ad3
authored
Oct 26, 2017
by
Kiste
Browse files
Implement downloading all semesters
parent
24922c81
Changes
1
Hide whitespace changes
Inline
Side-by-side
studsauger/logik.py
View file @
cec32ad3
...
...
@@ -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'
]:
fetch
semester
(
path
,
s
,
blacklist
,
semester
)
hol
semester
(
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment