Skip to content

Commit d256da9

Browse files
committed
added operation type header_value
1 parent 4f066e9 commit d256da9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

converter_app/converters.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,25 @@ def _run_operation(self, rows, operation):
297297
str_value = operation.get('value')
298298
elif operation.get('type') == 'metadata_value':
299299
str_value = self.input_tables[int(operation.get('table'))]['metadata'].get(operation.get('value'))
300+
elif operation.get('type') == 'header_value':
301+
table = 0
302+
if operation.get('table') is not None:
303+
table = int(operation.get('table'))
304+
line = operation.get('line')
305+
pattern = operation.get('regex')
306+
if line is not None and pattern is not None:
307+
str_value = self.input_tables[table]['header'][int(operation.get('line'))-1]
308+
match = re.search(pattern, str_value)
309+
if match is not None:
310+
if len(match.regs) > 1:
311+
str_value = match[1]
312+
else:
313+
str_value = match[0]
300314
else:
301315
raise ValueError(f"Unknown operation type: {operation.get('type')}")
302316
try:
303317
op_value = float(str_value)
304-
except TypeError:
318+
except (TypeError, ValueError):
305319
if operation.get('operator') in ('+', '-'):
306320
op_value = 0
307321
else:

0 commit comments

Comments
 (0)