WebApp Design modern
This commit is contained in:
parent
4c9a9eb91f
commit
16c97890e3
4 changed files with 169 additions and 8 deletions
81
app.py
81
app.py
|
|
@ -5,19 +5,98 @@ import sys
|
|||
import json
|
||||
from pathlib import Path
|
||||
from flask import redirect
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
BASE_DIR = Path(__file__).parent
|
||||
CATEGORIES_FILE = BASE_DIR / "Kategorien.json"
|
||||
|
||||
def get_current_week_data():
|
||||
|
||||
year, week, _ = datetime.now().isocalendar()
|
||||
|
||||
summary_file = (
|
||||
BASE_DIR
|
||||
/ "Transaktionen"
|
||||
/ str(year)
|
||||
/ "summary"
|
||||
/ f"category_summary_{year}_KW{week:02d}.json"
|
||||
)
|
||||
|
||||
transactions_file = (
|
||||
BASE_DIR
|
||||
/ "Transaktionen"
|
||||
/ str(year)
|
||||
/ "categorized_json"
|
||||
/ f"categorized_transactions_{year}_KW{week:02d}.json"
|
||||
)
|
||||
|
||||
summary = None
|
||||
transactions = []
|
||||
|
||||
total_income = 0
|
||||
total_expenses = 0
|
||||
total_saldo = 0
|
||||
|
||||
if summary_file.exists():
|
||||
|
||||
with open(
|
||||
summary_file,
|
||||
encoding="utf-8"
|
||||
) as f:
|
||||
|
||||
summary = json.load(f)
|
||||
|
||||
for values in summary.values():
|
||||
|
||||
total_income += values["income"]
|
||||
total_expenses += values["expenses"]
|
||||
total_saldo += values["saldo"]
|
||||
|
||||
if transactions_file.exists():
|
||||
|
||||
with open(
|
||||
transactions_file,
|
||||
encoding="utf-8"
|
||||
) as f:
|
||||
|
||||
transactions = json.load(f)
|
||||
|
||||
return (
|
||||
year,
|
||||
week,
|
||||
summary,
|
||||
transactions,
|
||||
total_income,
|
||||
total_expenses,
|
||||
total_saldo
|
||||
)
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
(
|
||||
year,
|
||||
week,
|
||||
summary,
|
||||
transactions,
|
||||
total_income,
|
||||
total_expenses,
|
||||
total_saldo
|
||||
) = get_current_week_data()
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
year=year,
|
||||
week=week,
|
||||
summary=summary,
|
||||
transactions=transactions[:10],
|
||||
total_income=total_income,
|
||||
total_expenses=total_expenses,
|
||||
total_saldo=total_saldo
|
||||
)
|
||||
@app.route("/run/balance", methods=["POST"])
|
||||
def run_balance():
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue