Creating a budget overview from a SuperX export.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.3 KiB

2 months ago
"""superx_budget
Creating a budget overview from a SuperX export
"""
__version__ = "0.0.1"
2 months ago
import argparse
import pathlib
import sys
import warnings
from .budget import parse_budget_file
2 months ago
from .exceptions import BudgetParserError, SuperXParserError # noqa: F401
from .helpers import ( # noqa: F401
find_budget_file,
2 months ago
find_recipients,
get_sheet_of_file,
is_budget_file_name,
2 months ago
list_budget_files,
)
from .overview import create_overview
2 months ago
from .pyramid import main # noqa: F401
from .superx import parse_exported_file
2 months ago
def cli_parse_exported_file():
parser = argparse.ArgumentParser(
prog="SuperxParserTest",
description="Try to parse a file exported from SuperX",
)
parser.add_argument("filename")
args = parser.parse_args()
2 months ago
with warnings.catch_warnings(action="ignore"):
sys.stderr.write(f"trying to read '{args.filename}'\n")
exported = parse_exported_file(pathlib.Path(args.filename))
2 months ago
sys.stderr.write("... OK\n")
sys.stderr.write(
f"searching budget file for year '{exported.account_year}'\n"
2 months ago
)
budget_dir = pathlib.Path(__file__).parent.parent / "budgets"
budget_file = find_budget_file(budget_dir, exported.account_year)
2 months ago
if not budget_file:
sys.exit("... no budget file found")
sys.stderr.write(f"... found '{budget_file}'\n")
sys.stderr.write(f"parsing budget file '{budget_file}'\n")
budget_data = parse_budget_file(budget_file)
sys.stderr.write("... OK\n")
sys.stderr.write("Creating overview\n")
2 months ago
overview_map = create_overview(budget_data, exported)
sys.stderr.write("... OK\n")
sys.stderr.write("Sorting overview\n")
# this here is the data from the overview template
2 months ago
overview = sorted(overview_map.values(), key=lambda i: i.row)
# this is a simple check if the overview data is not completly off
_ = str(overview)
2 months ago
sys.stderr.write("... OK\n")
sys.stderr.write("Geting recipients file\n")
recipients = find_recipients(budget_dir) # noqa: F841
2 months ago
sys.stderr.write("... OK\n")
sys.stderr.write("Retrieving sheet for export\n")
sheet = get_sheet_of_file(budget_file) # noqa: F841
sys.stderr.write("... OK\n")
sys.stderr.write("quick parser test did not find any errors\n")