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
a1fd6f0c
Commit
a1fd6f0c
authored
Nov 11, 2018
by
Julian Rother
Browse files
Move campusoffice-specific code into separate function
parent
dcfd3444
Changes
1
Show whitespace changes
Inline
Side-by-side
importer.py
View file @
a1fd6f0c
from
server
import
*
import
urllib.request
import
urllib.parse
@
app
.
route
(
'/internal/import/<int:id>'
,
methods
=
[
'GET'
,
'POST'
])
@
mod_required
def
list_import_sources
(
id
):
...
...
@@ -25,22 +28,10 @@ def list_import_sources(id):
return
render_template
(
'import_campus.html'
,
course
=
courses
,
import_campus
=
import_campus
,
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
:
def
fetch_co_course_events
(
i
):
from
lxml
import
html
from
lxml
import
etree
import
urllib.request
# if u have to port this to anything new, god be with you.
for
i
in
import_campus
:
events
=
[]
try
:
remote_html
=
urllib
.
request
.
urlopen
(
i
[
'url'
]).
read
()
except
:
...
...
@@ -118,9 +109,22 @@ def import_from(id):
e
[
'title'
]
=
i
[
'type'
]
events
.
append
(
e
)
# it is parsed.
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
)
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