Commit 27f35be0 authored by Andreas Valder's avatar Andreas Valder
Browse files

import fixes

parent aa240e0a
......@@ -328,9 +328,6 @@ def log():
@mod_required
def import_from(source=None, id=None):
def recursive_dict(element):
return element.tag, dict(map(recursive_dict, element)) or element.text
if source != "campus":
return "Unknown source", 404
......@@ -355,6 +352,7 @@ def import_from(source=None, id=None):
query('DELETE FROM import_campus WHERE (id = ?) AND (course_id = ?)',int(i),id)
import_campus = query('SELECT * FROM import_campus WHERE course_id = ?',id)
events = []
try:
from lxml import html
......@@ -394,7 +392,6 @@ def import_from(source=None, id=None):
# parse single appointments
singletable = basetable.xpath("//table[@cellpadding='3']/tr/td[text()='Einmalige Termine:']")[0].getparent().getparent()
# i['single']=html.tostring(singletable)
for row in singletable.xpath("tr/td[2]"):
rowdata = {}
rowdata['place'] = row.xpath("text()[2]")[0][2:-1]
......@@ -404,7 +401,6 @@ def import_from(source=None, id=None):
events_raw.append(rowdata)
#now we have to filter our data and do some lookups
events = []
for j in events_raw:
for k in j['dates']:
e = {}
......@@ -412,12 +408,21 @@ def import_from(source=None, id=None):
e['time'] = datetime.strptime("%s %s"%(k,j['start']) ,fmt)
e['duration'] = int((datetime.strptime("%s %s"%(k,j['end']) ,fmt) - e['time']).seconds/60)
e['place'] = query("SELECT name FROM places WHERE (campus_name = ?) OR ((NOT campus_name) AND name = ?)",j['place'],j['place'])[0]['name'];
e['exists'] = len(query("SELECT id from lectures WHERE (time = ?) and (duration = ?) and (place = ?) and (course_id = ?)",e['time'],e['duration'],e['place'],id)) > 0
events.append(e)
# it is pared.
i['events'] = events
except ImportError:
flash('python-lxml not found, campus import will not work.')
return render_template('import_campus.html', course=courses, lectures=lectures, import_campus=import_campus)
uniqevents = []
for i in events:
seen = False
for j in events:
seen = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration'])
if not seen:
uniqevents.append(i)
return render_template('import_campus.html', course=courses, lectures=lectures, import_campus=import_campus, events=uniqevents)
......@@ -55,5 +55,17 @@
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Fehlende Termine:</h1>
</div>
<ul class="list-group-item">
{% for i in events if not i.exists %}
<li class="list-group-item">
{{i|pprint}}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}
Supports Markdown
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