Skip to content

Commit d2a6555

Browse files
committed
cont
1 parent 188951e commit d2a6555

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

datapackage_pipelines_budgetkey/processors/dump_to_es.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ def format_datetime_rows(self, spec, rows):
4646
formatters = {}
4747
for f in spec['schema']['fields']:
4848
if f['type'] == 'datetime':
49+
logging.info('FIELD datetime: %r', f)
4950
if f.get('format', 'default') in ('any', 'default'):
50-
formatters[f['name']] = lambda x: x.strftime('%Y-%m-%dT%H:%M:%SZ')
51+
formatters[f['name']] = lambda x: None if x is None else x.strftime('%Y-%m-%dT%H:%M:%SZ')
5152
else:
52-
formatters[f['name']] = lambda x: x.strftime(f['format'])
53+
def formatter(f):
54+
fmt = f['format']
55+
def func(x):
56+
if x is None:
57+
return None
58+
else:
59+
return x.strftime(fmt)
60+
return func
61+
formatters[f['name']] = formatter(f)
5362
id = lambda x: x
5463

5564
for row in rows:

0 commit comments

Comments
 (0)