Browse Source

added parsing file functions

pull/1/head
Holger Frey 5 years ago
parent
commit
9b1786f9dc
  1. 7
      superx_budget/budget.py
  2. 15
      superx_budget/helpers.py
  3. 7
      superx_budget/superx.py
  4. 13
      tests/test_budget_parser.py
  5. 13
      tests/test_superx_parser.py

7
superx_budget/budget.py

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
from collections import namedtuple
from .helpers import get_sheet_of_file
from .exceptions import BudgetParserError
EXPECTED_TABLE_HEADERS = [
@ -60,3 +61,9 @@ def parse_budget_data(xls_sheet): @@ -60,3 +61,9 @@ def parse_budget_data(xls_sheet):
rows = (ExcelRow(i, v) for i, v in enumerate(xls_sheet.values, start=1))
_check_table_header(next(rows))
return list(_parse_data_table(rows))
def parse_budget_file(file_path):
""" parses the budget file """
sheet = get_sheet_of_file(file_path, name=None)
return parse_budget_data(sheet)

15
superx_budget/helpers.py

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
""" some helper functions """
import openpyxl
def get_sheet_of_file(excel_file, name=None):
""" returns a sheet from an excel FileCache
if name is set to None, the function returns the first sheet
"""
workbook = openpyxl.open(excel_file)
if name is None:
sheets = workbook.sheetnames
name = sheets[0]
return workbook[name]

7
superx_budget/superx.py

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
from datetime import datetime
from collections import namedtuple
from .helpers import get_sheet_of_file
from .exceptions import SuperXParserError
EXPECTED_HEADLINE = "Verwendungsnachweis und Kassenstand SAP"
@ -83,3 +84,9 @@ def parse_export_data(xls_sheet): @@ -83,3 +84,9 @@ def parse_export_data(xls_sheet):
_skip_export_data_until_table_header(rows)
data = list(_parse_data_table(rows))
return SuperXResult(metadata.account_year, metadata.export_date, data)
def parse_exported_file(file_path):
""" parses the budget file """
sheet = get_sheet_of_file(file_path, name=None)
return parse_export_data(sheet)

13
tests/test_budget_parser.py

@ -82,3 +82,16 @@ def test_parse_budget_data(example_sheet): @@ -82,3 +82,16 @@ def test_parse_budget_data(example_sheet):
assert last.number == "=A51+1"
assert last.project_name == "ZIM Microcoat II"
assert last.rest == "=E54-F54"
def test_parse_budget_file(example_file):
from superx_budget.budget import parse_budget_file
result = parse_budget_file(example_file)
first = result[0]
assert len(result) == 18
assert first.row == 3
assert first.number == 1
assert first.project_name == "Safegurard I (neu)"
assert first.rest == "=E3-F3"

13
tests/test_superx_parser.py

@ -140,3 +140,16 @@ def test_parse_export_data(example_workbook): @@ -140,3 +140,16 @@ def test_parse_export_data(example_workbook):
assert last.revenue_actual == 2236
assert last.revenue_target == 3236
assert last.acutal_value == 4236
def test_parse_exported_file(example_file):
from superx_budget.superx import parse_exported_file
result = parse_exported_file(example_file)
first = result.data[0]
assert len(result.data) == 212
assert first.cost_center == "1110200121"
assert first.fonds == "3310"
assert first.project == "1100000102"
assert first.kind == "1 - Personal"

Loading…
Cancel
Save