From d2a6555e43e83beb1b02d0243abdad3cb4459c97 Mon Sep 17 00:00:00 2001 From: Adam Kariv Date: Mon, 2 Jul 2018 11:26:12 +0300 Subject: [PATCH] cont --- .../processors/dump_to_es.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/datapackage_pipelines_budgetkey/processors/dump_to_es.py b/datapackage_pipelines_budgetkey/processors/dump_to_es.py index 338b13c6..09c5277c 100644 --- a/datapackage_pipelines_budgetkey/processors/dump_to_es.py +++ b/datapackage_pipelines_budgetkey/processors/dump_to_es.py @@ -46,10 +46,19 @@ def format_datetime_rows(self, spec, rows): formatters = {} for f in spec['schema']['fields']: if f['type'] == 'datetime': + logging.info('FIELD datetime: %r', f) if f.get('format', 'default') in ('any', 'default'): - formatters[f['name']] = lambda x: x.strftime('%Y-%m-%dT%H:%M:%SZ') + formatters[f['name']] = lambda x: None if x is None else x.strftime('%Y-%m-%dT%H:%M:%SZ') else: - formatters[f['name']] = lambda x: x.strftime(f['format']) + def formatter(f): + fmt = f['format'] + def func(x): + if x is None: + return None + else: + return x.strftime(fmt) + return func + formatters[f['name']] = formatter(f) id = lambda x: x for row in rows: