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

1 import logging

2 import os

3 from pprint import pprint

4 from django.core.management.base import CommandParser

5 from jbank.aeb43 import AEB43_STATEMENT_SUFFIXES, parse_aeb43_statements_from_file

6 from jbank.files import list_dir_files

7 from jbank.parsers import parse_filename_suffix

8 from jutil.command import SafeCommand

9

10 logger = logging.getLogger(__name__)

11

12

13 class Command(SafeCommand):

14 help = "Parses bank statement .AEB43 files"

15

16 def add_arguments(self, parser: CommandParser):

17 parser.add_argument("path", type=str)

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

19 parser.add_argument("--test", action="store_true")

20

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

22 files = list_dir_files(kwargs["path"])

23 for filename in files:

24 plain_filename = os.path.basename(filename)

25

26 if parse_filename_suffix(plain_filename).upper() not in AEB43_STATEMENT_SUFFIXES:

27 print("Ignoring non-AEB43 file {}".format(filename))

28 continue

29

30 batches = parse_aeb43_statements_from_file(filename)

31 pprint(batches)