mbank-to-mt940/main.py

46 lines
1.0 KiB
Python
Raw Normal View History

2020-02-17 09:54:00 +01:00
import argparse
2023-09-03 15:31:36 +02:00
from mbank import MbankCsvReader
2020-02-17 09:54:00 +01:00
from mt940 import Mt940Writer
def main():
parser = argparse.ArgumentParser(
2023-09-03 15:31:36 +02:00
prog="oddity-mbank-to-mt940",
description="Convert mBank CSV-files to MT940 format.",
)
2020-02-17 09:54:00 +01:00
2023-09-03 15:31:36 +02:00
parser.add_argument(
"--in", dest="input_file", help="path to Revolut csv-file", required=True
)
2020-02-17 09:54:00 +01:00
2023-09-03 15:31:36 +02:00
parser.add_argument(
"--out", dest="output_file", help="path to MT940 output path", required=True
)
2020-02-17 09:54:00 +01:00
args = parser.parse_args()
2023-09-03 15:31:36 +02:00
reader = MbankCsvReader(args.input_file)
2020-02-17 09:54:00 +01:00
2023-09-03 15:31:36 +02:00
print(reader.range)
with Mt940Writer(
args.output_file,
reader.iban,
reader.range,
reader.starting_balance,
reader.date_start,
) as writer:
transactions = reader.get_all_transactions()
for transaction in transactions:
2020-02-17 09:54:00 +01:00
writer.write_transaction(transaction)
2023-09-03 15:31:36 +02:00
print(
"Wrote {} transactions to file: {}.".format(
len(transactions), args.output_file
)
)
2020-02-17 09:54:00 +01:00
if __name__ == "__main__":
main()