from pathlib import Path from tests.factories import ( ComdirectCreditCardFactory, ComdirectDepotFactory, ComdirectGiroFactory, ) DEFAULT_PATH = Path("tests/test_data/comdirect_export_dummy_01.txt") TEMPLATE_PATH = Path("scripts/dummy_data/comdirect_export_template.txt") NUMBER_OF_ROWS_GIRO = 50 NUMBER_OF_ROWS_CREDIT = 20 NUMBER_OF_ROWS_TAGESGELD = 10 NUMBER_OF_ROWS_DEPOT = 10 def save(path: Path = DEFAULT_PATH): with TEMPLATE_PATH.open("r", encoding="latin-1") as fid: txt_temp = fid.read() assert isinstance(txt_temp, str) batches = { "giro": { "data": ComdirectGiroFactory.batch(NUMBER_OF_ROWS_GIRO), "table_txt": "", }, "credit": { "data": ComdirectCreditCardFactory.batch(NUMBER_OF_ROWS_CREDIT), "table_txt": "", }, "tagesgled": { "data": ComdirectGiroFactory.batch(NUMBER_OF_ROWS_TAGESGELD), "table_txt": "", }, "depot": { "data": ComdirectDepotFactory.batch(NUMBER_OF_ROWS_DEPOT), "table_txt": "", }, } for batch in batches.values(): data = batch.get("data") assert isinstance(data, list) lines = [data[0].get_orig_headers()] lines = lines + [row.get_orig_row() for row in data] batch["table_txt"] = "\n".join(lines) txt = txt_temp.format( table_giro=batches["giro"]["table_txt"], table_credit_card=batches["credit"]["table_txt"], table_tagesgeld=batches["tagesgled"]["table_txt"], table_depot=batches["depot"]["table_txt"], ) with path.open("w", newline="") as fid: fid.write(txt) if __name__ == "__main__": save()