-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive_expenses_report.py
57 lines (45 loc) · 1.59 KB
/
interactive_expenses_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Script to process the data included in the CSV
"""
import os
import re
from lib.graphs import (
get_category_average_bar_graphs,
get_overview_graphs,
get_category_detailed_bar_graphs,
)
from lib.html_report import generate_report
from lib.stats import get_categories_by_year_with_subcategory
from lib.transaction import read_transactions
from settings import INPUT_DIR
def get_input_files() -> list[str]:
"""
Get all the CSV files stored in INPUT_DIR, this allows to do partial exports periodically
without relying on exporting all the old data
"""
root = os.path.dirname(os.path.abspath(__file__))
input_dir = os.path.join(root, INPUT_DIR)
csv_files: list[str] = []
for file in os.listdir(input_dir):
if re.search(r".csv$", file):
csv_files.append(os.path.join(input_dir, file))
if not csv_files:
raise ValueError(f"No *.csv files where found in {input_dir}")
return csv_files
def main():
"""
Main functionality of this project
"""
transactions = read_transactions(get_input_files())
overview_graphs = get_overview_graphs(transactions)
category_details_graphs = get_category_detailed_bar_graphs(transactions)
category_avg_graphs = get_category_average_bar_graphs(transactions)
year_expenses = get_categories_by_year_with_subcategory(transactions)
generate_report(
graphs_overview=overview_graphs,
graphs_category_details=category_details_graphs,
graphs_category_avg=category_avg_graphs,
year_expenses=year_expenses,
)
if __name__ == "__main__":
main()