[Dive4elements-commits] [PATCH] Importer: Handle empty year fields in dgm csv

Wald Commits scm-commit at wald.intevation.org
Mon Mar 11 11:20:38 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1362997232 -3600
# Node ID 76818dc2c937bb411de2511c56e7000813cfd6fd
# Parent  14186e9245346411c809c5e4084aad0a71618cf2
Importer: Handle empty year fields in dgm csv

diff -r 14186e924534 -r 76818dc2c937 flys-backend/contrib/shpimporter/dgm.py
--- 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()


More information about the Dive4elements-commits mailing list