Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Hellenkamp
website
Commits
8767a8cf
Commit
8767a8cf
authored
6 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Add rwth-online-importer
parent
a1fd6f0c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
importer.py
+49
-4
49 additions, 4 deletions
importer.py
with
49 additions
and
4 deletions
importer.py
+
49
−
4
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
:
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.
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment