Coverage for jbank/management/commands/parse_ra.py: 0%

1 import logging

2 from pprint import pprint

3 from django.core.management.base import CommandParser

4 from jbank.services import create_account_balance

5 from jbank.parsers import parse_samlink_real_time_statement

6 from jutil.command import SafeCommand

7

8 logger = logging.getLogger(__name__)

9

10

11 class Command(SafeCommand):

12 help = "Parses Samlink RA file type"

13

14 def add_arguments(self, parser: CommandParser):

15 parser.add_argument("filename", type=str)

16 parser.add_argument("--bic", type=str, default="")

17 parser.add_argument("--pprint", action="store_true")

18 parser.add_argument("--store", action="store_true")

19

20 def do(self, *args, **kwargs):

21 filename = kwargs["filename"]

22 with open(filename, "rt", encoding="ISO-8859-1") as fp:

23 content = fp.read()

24 res = parse_samlink_real_time_statement(content)

25 if kwargs["store"]:

26 logger.info("%s created", create_account_balance(bic=kwargs["bic"], **res))

27 pprint(res)