Mercurial > dive4elements > river
diff flys-backend/contrib/shpimporter/dgm.py @ 5213:76818dc2c937
Importer: Handle empty year fields in dgm csv
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 11 Mar 2013 11:20:32 +0100 |
parents | 908848b74d7e |
children | 3b86bf214d53 |
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/dgm.py Mon Mar 11 10:12:55 2013 +0100 +++ b/flys-backend/contrib/shpimporter/dgm.py Mon Mar 11 11:20:32 2013 +0100 @@ -7,6 +7,10 @@ def latin(string): return unicode(string, "latin1") +import logging +logger = logging.getLogger("DGM") + + # <dbfield> : (<csvfield>, conversion function) DGM_MAP = { "projection" : "Projektion", @@ -82,6 +86,8 @@ return idx def get_time_interval_id(cur, a, b, oracle): + if not a or not b: + return None if oracle: cur.execute(SQL_SELECT_TIME_ID_ORA, (a, b)) else: @@ -122,10 +128,15 @@ fields[namedict[val]], "UTF-8")) km_von = fields[namedict["km_von"]] km_bis = fields[namedict["km_bis"]] - year_from = datetime.datetime( - int(fields[namedict["Jahr_von"]]), 1, 1) - year_to = datetime.datetime( - int(fields[namedict["Jahr_bis"]]),1 ,1) + year_from = None + year_to = None + try: + year_from = datetime.datetime( + int(fields[namedict["Jahr_von"]]), 1, 1) + year_to = datetime.datetime( + int(fields[namedict["Jahr_bis"]]),1 ,1) + except ValueError: + logger.warn("Invalid numbers (or none) found in year_from and year_to") name = "%s KM %s - %s" % (river_name, km_von, km_bis) cur = dbconn.cursor()