mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-14 00:38:46 +02:00
refactor: Move quote removal funtion to string utils, adapt to requirements
This commit is contained in:
parent
2a446a9937
commit
259259953e
@ -25,7 +25,10 @@ from aki_prj23_transparenzregister.models.company import (
|
|||||||
PersonToCompanyRelationship,
|
PersonToCompanyRelationship,
|
||||||
RelationshipRoleEnum,
|
RelationshipRoleEnum,
|
||||||
)
|
)
|
||||||
from aki_prj23_transparenzregister.utils.string_tools import transform_date_to_iso
|
from aki_prj23_transparenzregister.utils.string_tools import (
|
||||||
|
remove_traling_and_leading_quotes,
|
||||||
|
transform_date_to_iso,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def transform_xml_to_json(source_dir: str, target_dir: str) -> None:
|
def transform_xml_to_json(source_dir: str, target_dir: str) -> None:
|
||||||
@ -63,9 +66,11 @@ def parse_stakeholder(data: dict) -> CompanyRelationship | None:
|
|||||||
if data["Beteiligter"]["Natuerliche_Person"]["Voller_Name"]["Vorname"] is None:
|
if data["Beteiligter"]["Natuerliche_Person"]["Voller_Name"]["Vorname"] is None:
|
||||||
return CompanyToCompanyRelationship(
|
return CompanyToCompanyRelationship(
|
||||||
**{
|
**{
|
||||||
"name": data["Beteiligter"]["Natuerliche_Person"]["Voller_Name"][
|
"name": remove_traling_and_leading_quotes(
|
||||||
|
data["Beteiligter"]["Natuerliche_Person"]["Voller_Name"][
|
||||||
"Nachname"
|
"Nachname"
|
||||||
].replace('"', ""),
|
]
|
||||||
|
),
|
||||||
"location": Location(
|
"location": Location(
|
||||||
**{
|
**{
|
||||||
"city": data["Beteiligter"]["Natuerliche_Person"][
|
"city": data["Beteiligter"]["Natuerliche_Person"][
|
||||||
@ -128,9 +133,11 @@ def parse_stakeholder(data: dict) -> CompanyRelationship | None:
|
|||||||
"role": RelationshipRoleEnum(
|
"role": RelationshipRoleEnum(
|
||||||
data["Rolle"]["Rollenbezeichnung"]["content"]
|
data["Rolle"]["Rollenbezeichnung"]["content"]
|
||||||
),
|
),
|
||||||
"name": data["Beteiligter"]["Organisation"]["Bezeichnung"][
|
"name": remove_traling_and_leading_quotes(
|
||||||
|
data["Beteiligter"]["Organisation"]["Bezeichnung"][
|
||||||
"Bezeichnung_Aktuell"
|
"Bezeichnung_Aktuell"
|
||||||
].replace('"', ""),
|
]
|
||||||
|
),
|
||||||
"location": Location(
|
"location": Location(
|
||||||
**{
|
**{
|
||||||
"city": data["Beteiligter"]["Organisation"]["Anschrift"]["Ort"],
|
"city": data["Beteiligter"]["Organisation"]["Anschrift"]["Ort"],
|
||||||
|
@ -34,3 +34,24 @@ def transform_date_to_iso(date: str) -> str:
|
|||||||
input_format = "%d.%m.%y" if re.match(regex_yy, date) else "%d.%m.%Y"
|
input_format = "%d.%m.%y" if re.match(regex_yy, date) else "%d.%m.%Y"
|
||||||
date_temp = datetime.strptime(date, input_format)
|
date_temp = datetime.strptime(date, input_format)
|
||||||
return date_temp.strftime("%Y-%m-%d")
|
return date_temp.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_traling_and_leading_quotes(value: str) -> str:
|
||||||
|
"""Removes trailing and leading doulbe-quotes from given string if present.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (str): _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: _description_
|
||||||
|
"""
|
||||||
|
if value is not None:
|
||||||
|
count_quotes = value.count('"')
|
||||||
|
if count_quotes > 0:
|
||||||
|
if value.startswith('"') and count_quotes % 2 != 0:
|
||||||
|
value = value[1:]
|
||||||
|
if value.endswith('"') and count_quotes % 2 != 0:
|
||||||
|
value = value[:-1]
|
||||||
|
if value.startswith('"') and value.endswith('"'):
|
||||||
|
value = value[1:-1]
|
||||||
|
return value
|
||||||
|
@ -45,3 +45,17 @@ def test_simplify_string_type_error(value: Any) -> None:
|
|||||||
def test_transform_date_to_iso(value: str, expected: str) -> None:
|
def test_transform_date_to_iso(value: str, expected: str) -> None:
|
||||||
result = string_tools.transform_date_to_iso(value)
|
result = string_tools.transform_date_to_iso(value)
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("value", "expected_result"),
|
||||||
|
[
|
||||||
|
(None, None),
|
||||||
|
('"Siemes Verwaltungs-GmbH"', "Siemes Verwaltungs-GmbH"),
|
||||||
|
('"Hans"-Wurst GmbH', '"Hans"-Wurst GmbH'),
|
||||||
|
('Hans-Wurst GmbH"', "Hans-Wurst GmbH"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_remove_trailing_and_leading_quotes(value: str, expected_result: str) -> None:
|
||||||
|
result = string_tools.remove_traling_and_leading_quotes(value)
|
||||||
|
assert result == expected_result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user