diff --git a/importer.py b/importer.py index 99a5f75101bfe6cec1ec7ef19f790b673dc56920..431a505ee19d5c8e157dc3057d574481bef59520 100644 --- a/importer.py +++ b/importer.py @@ -68,7 +68,13 @@ def import_from(id): continue baserow = baserow[0] rowdata = {'dates': []} - rowdata['place'] = baserow.xpath("td[6]/text()")[0][2:-1] + + # "kein raum vergeben" ist ein Sonderfall, ansonsten die campus id + if baserow.xpath("td[6]/text()")[0] == 'Kein Raum vergeben': + rowdata['place'] = '' + else: + rowdata['place'] = baserow.xpath("td[6]/a")[0].text_content() + rowdata['start'] = baserow.xpath("td[3]/text()")[0] rowdata['end'] = baserow.xpath("td[5]/text()")[0] rowdata['dates'] = baserow.getparent().xpath("tr[@class='hierarchy5']//td[@colspan='3']/text()") @@ -79,7 +85,11 @@ def import_from(id): singletable = basetable.xpath("//table[@cellpadding='3']/tr/td[text()='Einmalige Termine:']")[0].getparent().getparent() for row in singletable.xpath("tr/td[2]"): rowdata = {} - rowdata['place'] = row.xpath("text()[2]")[0][2:-1] + if row.xpath("text()[2]")[0] == 'Kein Raum vergeben': + rowdata['place'] = '' + else: + rowdata['place'] = row.xpath("a")[0].text_content() + 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] @@ -92,11 +102,14 @@ def import_from(id): 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) - dbplace = query("SELECT name FROM places WHERE (campus_name = ?) OR ((NOT campus_name) AND name = ?)",j['place'],j['place']) - if dbplace: - e['place'] = dbplace[0]['name'] + if j['place'] != '': + dbplace = query("SELECT name FROM places WHERE (campus_room = ?) OR (campus_name = ?) OR ((NOT campus_name) AND name = ?)",j['place'],j['place'],j['place']) + if dbplace: + e['place'] = dbplace[0]['name'] + else: + e['place'] = 'Unbekannter Ort ('+j['place']+')' else: - e['place'] = 'Unbekannter Ort ('+j['place']+')' + e['place'] = '' e['title'] = i['type'] events.append(e) # it is parsed.