Skip to content

Commit

Permalink
Move processing "filtered" notebook to own function
Browse files Browse the repository at this point in the history
  • Loading branch information
meddlin committed Feb 25, 2024
1 parent 5d74830 commit 82be739
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
48 changes: 18 additions & 30 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ def create_full_workbook(workbook, worksheet, full: dict[str, str]):
autofit_columns(worksheet)
configure_filters(worksheet, full_sheet_row_counter, num_of_cols)

def create_filtered_workbook(workbook, worksheet, abridged: dict[str, str], filter_columns: list[str]):
workbook.active = worksheet
worksheet.append(filter_columns)
bold_header(worksheet) # NOTE: Must execute AFTER data has been written to the header row.

row_counter = 0
abr_num_of_cols = len(abridged[0].keys())
abr_col_names = list(abridged[0].keys())
for row in abridged:
# TODO: Add ability to *add* columns instead of only filter what is already there.
# ws1.append([row['Posting Date'], row['Amount'], row['Description'], row['Transaction Category'], row['Extended Description']])
worksheet.append( utility.get_row_filtered(row, abr_col_names, filter_columns) )
row_counter += 1

autofit_columns(worksheet)
configure_filters(worksheet, row_counter, abr_num_of_cols)

def create_workbooks(full: dict[str, str], abridged: dict[str, str], filter_columns: str, sheet_name: str, output: str):
"""Create workbooks and control what changes are made to them. (This is where the magic happens)"""

Expand All @@ -98,37 +115,8 @@ def create_workbooks(full: dict[str, str], abridged: dict[str, str], filter_colu
ws1 = wb.create_sheet(sheet_name)
ws2 = wb.create_sheet('raw_data')

wb.active = ws1
ws1.append(filter_columns)
bold_header(ws1) # NOTE: Must execute AFTER data has been written to the header row.

row_counter = 0
abr_num_of_cols = len(abridged[0].keys())
abr_col_names = list(abridged[0].keys())
for row in abridged:
# TODO: Add ability to *add* columns instead of only filter what is already there.
# ws1.append([row['Posting Date'], row['Amount'], row['Description'], row['Transaction Category'], row['Extended Description']])
ws1.append( utility.get_row_filtered(row, abr_col_names, filter_columns) )
row_counter += 1

autofit_columns(ws1)
configure_filters(ws1, row_counter, abr_num_of_cols)

create_filtered_workbook(workbook=wb, worksheet=ws1, abridged=abridged, filter_columns=filter_columns)
create_full_workbook(workbook=wb, worksheet=ws2, full=full)
# wb.active = ws2
# num_of_cols = len(full[0].keys())
# col_names = list(full[0].keys())

# ws2.append(col_names) # NOTE: Creates header row
# bold_header(ws2) # NOTE: Must execute AFTER data has been written to the header row.
# full_sheet_row_counter = 0

# for f_row in full:
# ws2.append( utility.get_row(f_row, col_names) )
# full_sheet_row_counter += 1

# autofit_columns(ws2)
# configure_filters(ws2, full_sheet_row_counter, num_of_cols)

set_zoom_scale(wb)
wb.save(output)
Expand Down
4 changes: 2 additions & 2 deletions utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_row(row: dict[str, str], column_names: list[str]):
return data

def get_row_filtered(row: dict[str, str], column_names: list[str], filter_columns: list[str]):
""" """
""""""

data = []
for col in column_names:
Expand All @@ -17,7 +17,7 @@ def get_row_filtered(row: dict[str, str], column_names: list[str], filter_column
return data

def format_filter_cols(filter_cs_list: str):
""" Separate filter columns.
"""Separate filter columns.
Remove leading and trailiing whitespace from filter columns.
Return as a list.
"""
Expand Down

0 comments on commit 82be739

Please sign in to comment.