fix: resolve CI linting and type checking issues
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
25
app/cmdparse/extractors.py
Normal file
25
app/cmdparse/extractors.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"""Field extraction utilities."""
|
||||||
|
|
||||||
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
|
||||||
|
def extract_fields(data: List[Dict[str, Any]], fields: List[str]) -> List[Dict[str, Any]]:
|
||||||
|
"""Extract specified fields from parsed data."""
|
||||||
|
result = []
|
||||||
|
for item in data:
|
||||||
|
extracted = {}
|
||||||
|
for field in fields:
|
||||||
|
if '.' in field:
|
||||||
|
parts = field.split('.')
|
||||||
|
value = item
|
||||||
|
for part in parts:
|
||||||
|
if isinstance(value, dict):
|
||||||
|
value = value.get(part)
|
||||||
|
else:
|
||||||
|
value = None
|
||||||
|
break
|
||||||
|
extracted[field] = value
|
||||||
|
else:
|
||||||
|
extracted[field] = item.get(field)
|
||||||
|
result.append(extracted)
|
||||||
|
return result
|
||||||
Reference in New Issue
Block a user