comparison 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
comparison
equal deleted inserted replaced
5212:14186e924534 5213:76818dc2c937
4 import utils 4 import utils
5 import datetime 5 import datetime
6 6
7 def latin(string): 7 def latin(string):
8 return unicode(string, "latin1") 8 return unicode(string, "latin1")
9
10 import logging
11 logger = logging.getLogger("DGM")
12
9 13
10 # <dbfield> : (<csvfield>, conversion function) 14 # <dbfield> : (<csvfield>, conversion function)
11 DGM_MAP = { 15 DGM_MAP = {
12 "projection" : "Projektion", 16 "projection" : "Projektion",
13 "elevation_state" : latin("Höhenstatus"), 17 "elevation_state" : latin("Höhenstatus"),
80 cur.execute(SQL_INSERT_RANGE_ID, (idx, river_id, a, b)) 84 cur.execute(SQL_INSERT_RANGE_ID, (idx, river_id, a, b))
81 cur.connection.commit() 85 cur.connection.commit()
82 return idx 86 return idx
83 87
84 def get_time_interval_id(cur, a, b, oracle): 88 def get_time_interval_id(cur, a, b, oracle):
89 if not a or not b:
90 return None
85 if oracle: 91 if oracle:
86 cur.execute(SQL_SELECT_TIME_ID_ORA, (a, b)) 92 cur.execute(SQL_SELECT_TIME_ID_ORA, (a, b))
87 else: 93 else:
88 cur.execute(SQL_SELECT_TIME_ID, (a, b)) 94 cur.execute(SQL_SELECT_TIME_ID, (a, b))
89 row = cur.fetchone() 95 row = cur.fetchone()
120 else: 126 else:
121 values.append(unicode.encode( 127 values.append(unicode.encode(
122 fields[namedict[val]], "UTF-8")) 128 fields[namedict[val]], "UTF-8"))
123 km_von = fields[namedict["km_von"]] 129 km_von = fields[namedict["km_von"]]
124 km_bis = fields[namedict["km_bis"]] 130 km_bis = fields[namedict["km_bis"]]
125 year_from = datetime.datetime( 131 year_from = None
126 int(fields[namedict["Jahr_von"]]), 1, 1) 132 year_to = None
127 year_to = datetime.datetime( 133 try:
128 int(fields[namedict["Jahr_bis"]]),1 ,1) 134 year_from = datetime.datetime(
135 int(fields[namedict["Jahr_von"]]), 1, 1)
136 year_to = datetime.datetime(
137 int(fields[namedict["Jahr_bis"]]),1 ,1)
138 except ValueError:
139 logger.warn("Invalid numbers (or none) found in year_from and year_to")
129 140
130 name = "%s KM %s - %s" % (river_name, km_von, km_bis) 141 name = "%s KM %s - %s" % (river_name, km_von, km_bis)
131 cur = dbconn.cursor() 142 cur = dbconn.cursor()
132 range_id = get_range_id(cur, river_id, float(km_von), 143 range_id = get_range_id(cur, river_id, float(km_von),
133 float(km_bis), oracle) 144 float(km_bis), oracle)

http://dive4elements.wald.intevation.org