Skip to content

Commit

Permalink
added operation type header_value
Browse files Browse the repository at this point in the history
  • Loading branch information
headri committed Mar 4, 2025
1 parent c8b3840 commit 9e6439c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion converter_app/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,25 @@ def _run_operation(self, rows, operation):
str_value = operation.get('value')
elif operation.get('type') == 'metadata_value':
str_value = self.input_tables[int(operation.get('table'))]['metadata'].get(operation.get('value'))
elif operation.get('type') == 'header_value':
table = 0
if operation.get('table') is not None:
table = int(operation.get('table'))
line = operation.get('line')
pattern = operation.get('regex')
if line is not None and pattern is not None:
str_value = self.input_tables[table]['header'][int(operation.get('line'))-1]
match = re.search(pattern, str_value)
if match is not None:
if len(match.regs) > 1:
str_value = match[1]
else:
str_value = match[0]
else:
raise ValueError(f"Unknown operation type: {operation.get('type')}")
try:
op_value = float(str_value)
except TypeError:
except (TypeError, ValueError):
if operation.get('operator') in ('+', '-'):
op_value = 0
else:
Expand Down

0 comments on commit 9e6439c

Please sign in to comment.