Commit aa240e0a authored by Andreas Valder's avatar Andreas Valder
Browse files

working and full parser for campus office. burn it to the ground. please.

parent bb362a6e
......@@ -325,7 +325,6 @@ def log():
return render_template('log.html', changelog=changelog)
@app.route('/import/<source>/<int:id>', methods=['GET', 'POST'])
#@handle_errors('course', 'Diese Veranstaltung existiert nicht!', 404, IndexError)
@mod_required
def import_from(source=None, id=None):
......@@ -399,13 +398,23 @@ def import_from(source=None, id=None):
for row in singletable.xpath("tr/td[2]"):
rowdata = {}
rowdata['place'] = row.xpath("text()[2]")[0][2:-1]
rowdata['date'] = row.xpath("text()[1]")[0][4:14]
rowdata['dates'] = [row.xpath("text()[1]")[0][4:14]]
rowdata['start'] = row.xpath("text()[1]")[0][17:22]
rowdata['end'] = row.xpath("text()[1]")[0][27:32]
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 = {}
fmt= "%d.%m.%Y %H:%M"
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'];
events.append(e)
# it is pared.
i['events'] = events
i['events_raw'] = events_raw
except ImportError:
flash('python-lxml not found, campus import will not work.')
......
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