Commit a1fd6f0c authored by Julian Rother's avatar Julian Rother
Browse files

Move campusoffice-specific code into separate function

parent dcfd3444
from server import * from server import *
import urllib.request
import urllib.parse
@app.route('/internal/import/<int:id>', methods=['GET', 'POST']) @app.route('/internal/import/<int:id>', methods=['GET', 'POST'])
@mod_required @mod_required
def list_import_sources(id): def list_import_sources(id):
...@@ -25,22 +28,10 @@ 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=[]) return render_template('import_campus.html', course=courses, import_campus=import_campus, events=[])
@app.route('/internal/import/<int:id>/now', methods=['GET', 'POST']) def fetch_co_course_events(i):
@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:
from lxml import html from lxml import html
from lxml import etree from lxml import etree
import urllib.request events = []
# if u have to port this to anything new, god be with you.
for i in import_campus:
try: try:
remote_html = urllib.request.urlopen(i['url']).read() remote_html = urllib.request.urlopen(i['url']).read()
except: except:
...@@ -118,9 +109,22 @@ def import_from(id): ...@@ -118,9 +109,22 @@ def import_from(id):
e['title'] = i['type'] e['title'] = i['type']
events.append(e) events.append(e)
# it is parsed. # 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: except ImportError:
flash('python-lxml not found, campus import will not work.') flash('python-lxml not found, campus import will not work.')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment