Skip to content
Snippets Groups Projects
Commit a1fd6f0c authored by Julian Rother's avatar Julian Rother
Browse files

Move campusoffice-specific code into separate function

parent dcfd3444
No related branches found
No related tags found
No related merge requests found
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.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment