import re from typing import NamedTuple class Transaction(NamedTuple): collaborator_id: int report_id: int statement_period_id: int type: str original_amount: str chargeable_amount: str currency: str date: str description: str creation_batch_uuid: str def get_transaction_description(report, report_run, date): return _sanitize( "_".join( [ report_run["name"], report.collaborator_name, report_run["period_name"], date, ] ) ) def _sanitize(text): """Remove spaces and replace all non-word characters with _. Args: text (str): text to sanitize Returns: str """ return re.sub(r"[^\w_-]", "_", text.replace(" ", ""))