if not value: return None
if value == 'Ja': return True
if value == 'Nein': return False
- raise Exception('%s is not a valid boolean value' % value)
+ raise Exception('%s is not a valid boolean value, use one of "Ja" or "Nein"' % value)
def to_geo(value):
It stores them in the database in case of success and returns a list of tuples (page_id, page_title) of successfully processed pages.
It raises an exception in case of errors and does not change the database."""
+ def to_bool_f(value, fieldname):
+ "Like 'to_bool' but adds the field name to the exception description"
+ try: return to_bool(value)
+ except Exception, e:
+ raise Exception("Error converting to bool in field %s: %s" % (fieldname, e.message))
+
+ def to_geo_f(value, fieldname):
+ "Like 'to_geo' but adds the field name to the exception description"
+ try: return to_geo(value)
+ except Exception, e:
+ raise Exception("Error converting to geo-coordinates in field %s: %s" % (fieldname, e.message))
+
def process_row(row):
"It converts a database row to a dictionary and performs checks."
(page_id, rev_id, old_id, page_title, old_text, under_construction) = row
properties[property] = None
# Match Rodelbahnbox
match = regexp.search(old_text)
- if not match:
+ if not match:
raise Exception("No 'Rodelbahnbox' found")
box = match.group(1)
# Process Rodelbahnbox
elif key == u'Gehzeit' and value: properties['walktime'] = int(value)
elif key == u'Höhe oben' and value: properties['height_top'] = int(value)
elif key == u'Höhe unten' and value: properties['height_bottom'] = int(value)
- elif key == u'Aufstieg getrennt': properties['walkup_separate'] = to_bool(value)
- elif key == u'Lift': properties['lift'] = to_bool(value)
- elif key == u'Beleuchtung': properties['night_light'] = to_bool(value)
- elif key == u'Rodelverleih': properties['sledge_rental'] = to_bool(value)
- elif key == u'Öffentliche Anreise': properties['public_transport'] = to_bool(value)
+ elif key == u'Aufstieg getrennt': properties['walkup_separate'] = to_bool_f(value, u'Aufstieg getrennt')
+ elif key == u'Lift': properties['lift'] = to_bool_f(value, u'Lift')
+ elif key == u'Beleuchtung': properties['night_light'] = to_bool_f(value, u'Beleuchtung')
+ elif key == u'Rodelverleih': properties['sledge_rental'] = to_bool_f(value, u'Rodelverleih')
+ elif key == u'Öffentliche Anreise': properties['public_transport'] = to_bool_f(value, u'Öffentliche Anreise')
elif key == u'Bild': properties['image'] = value
- elif key == u'Position': (properties['position_latitude'], properties['position_longitude']) = to_geo(value) # '47.583333 N 15.75 E'
- elif key == u'Auskunft': properties['information'] = value
- elif key == u'In Übersichtskarte': properties['show_in_overview'] = to_bool(value)
+ elif key == u'Position': (properties['position_latitude'], properties['position_longitude']) = to_geo_f(value, u'Position') # '47.583333 N 15.75 E'
+ elif key == u'Auskunft': properties['information'] = value
+ elif key == u'In Übersichtskarte': properties['show_in_overview'] = to_bool_f(value, u'In Übersichtskarte')
elif key == u'Aufnahmedatum': properties['creation_date'] = value # '2006-03-15'
properties['page_id'] = page_id
properties['page_title'] = to_title(page_title)