Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Roman Karwacik
website
Commits
8767a8cf
Commit
8767a8cf
authored
Nov 11, 2018
by
Julian Rother
Browse files
Add rwth-online-importer
parent
a1fd6f0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
importer.py
View file @
8767a8cf
...
...
@@ -111,20 +111,65 @@ def fetch_co_course_events(i):
# it is parsed.
return
events
def
fetch_ro_event_ical
(
ids
):
data
=
{
'pMode'
:
'T'
,
'pInclPruef'
:
'N'
,
'pInclPruefGepl'
:
'N'
,
'pOutputFormat'
:
'99'
,
'pCharset'
:
'UTF8'
,
'pMaskAction'
:
'DOWNLOAD'
}
data
=
list
(
data
.
items
())
for
id
in
ids
:
data
.
append
((
'pTerminNr'
,
id
))
data
=
urllib
.
parse
.
urlencode
(
data
).
encode
(
'utf-8'
)
r
=
urllib
.
request
.
Request
(
'https://online.rwth-aachen.de/RWTHonline/pl/ui/%24ctx/wbKalender.wbExport'
,
data
=
data
,
method
=
'POST'
)
with
urllib
.
request
.
urlopen
(
r
)
as
f
:
return
f
.
read
().
decode
(
'utf-8'
)
def
fetch_ro_course_ical
(
id
):
from
lxml
import
html
url
=
'https://online.rwth-aachen.de/RWTHonline/pl/ui/%24ctx/wbTermin_List.wbLehrveranstaltung?pStpSpNr='
+
'%i'
%
(
int
(
id
))
req
=
urllib
.
request
.
urlopen
(
url
)
dom
=
html
.
fromstring
(
req
.
read
())
event_ids
=
[
x
.
value
for
x
in
dom
.
xpath
(
'//input[@name="pTerminNr"]'
)]
return
fetch_ro_event_ical
(
event_ids
)
def
fetch_ro_course_events
(
item
):
import
icalendar
# First fix crappy javascript fragment-Paths
url
=
urllib
.
parse
.
urlparse
(
item
[
'url'
].
replace
(
'#/'
,
''
))
args
=
urllib
.
parse
.
parse_qs
(
url
.
query
)
if
'pStpSpNr'
in
args
:
# Legacy URLs
id
=
args
[
'pStpSpNr'
][
0
]
elif
url
.
path
.
split
(
'/'
)[
-
2
]
==
'courses'
:
# New URLs
id
=
url
.
path
.
split
(
'/'
)[
-
1
]
else
:
flash
(
"Ungültige URL: '"
+
i
[
'url'
]
+
"'"
)
cal
=
icalendar
.
Calendar
().
from_ical
(
fetch_ro_course_ical
(
id
))
events
=
[]
for
comp
in
cal
.
subcomponents
:
if
comp
.
name
!=
'VEVENT'
:
continue
if
comp
.
get
(
'STATUS'
)
!=
'CONFIRMED'
:
continue
e
=
{}
e
[
'place'
]
=
str
(
comp
.
get
(
'LOCATION'
,
''
))
e
[
'time'
]
=
comp
[
'DTSTART'
].
dt
# TODO: tz
e
[
'duration'
]
=
int
((
comp
[
'DTEND'
].
dt
-
comp
[
'DTSTART'
].
dt
).
seconds
/
60
)
e
[
'title'
]
=
item
[
'type'
]
events
.
append
(
e
)
return
events
@
app
.
route
(
'/internal/import/<int:id>/now'
,
methods
=
[
'GET'
,
'POST'
])
@
mod_required
def
import_from
(
id
):
courses
=
query
(
'SELECT * FROM courses WHERE id = ?'
,
id
)[
0
]
lectures
=
query
(
'SELECT * FROM lectures WHERE course_id = ?'
,
courses
[
'id'
])
import_campus
=
query
(
'SELECT * FROM import_campus WHERE course_id = ?'
,
id
)
events
=
[]
try
:
# if u have to port this to anything new, god be with you.
for
i
in
import_campus
:
events
+=
fetch_co_course_events
(
i
)
if
'www.campus.rwth-aachen.de'
in
i
[
'url'
]:
events
+=
fetch_co_course_events
(
i
)
else
:
events
+=
fetch_ro_course_events
(
i
)
except
ImportError
:
flash
(
'python-lxml not found, campus import will not work.'
)
...
...
Write
Preview
Markdown
is supported
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