WebApp
This commit is contained in:
parent
d6e6f01329
commit
af9e2fc138
3 changed files with 178 additions and 0 deletions
92
app.py
Normal file
92
app.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
from pathlib import Path
|
||||
from flask import Flask, render_template, request
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
BASE_DIR = Path(__file__).parent
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route("/run/balance", methods=["POST"])
|
||||
def run_balance():
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(BASE_DIR / "balance.py")],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="balance.py",
|
||||
output=result.stdout + result.stderr
|
||||
)
|
||||
|
||||
|
||||
@app.route("/run/transactions", methods=["POST"])
|
||||
def run_transactions():
|
||||
|
||||
year = request.form.get("year", "").strip()
|
||||
week = request.form.get("week", "").strip()
|
||||
|
||||
command = [
|
||||
sys.executable,
|
||||
str(BASE_DIR / "transactions.py")
|
||||
]
|
||||
|
||||
if year and week:
|
||||
command.extend([year, week])
|
||||
|
||||
result = subprocess.run(
|
||||
command,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="transactions.py",
|
||||
output=result.stdout + result.stderr
|
||||
)
|
||||
|
||||
|
||||
@app.route("/run/categorize", methods=["POST"])
|
||||
def run_categorize():
|
||||
|
||||
year = request.form.get("year", "").strip()
|
||||
week = request.form.get("week", "").strip()
|
||||
|
||||
command = [
|
||||
sys.executable,
|
||||
str(BASE_DIR / "categorize_transactions.py")
|
||||
]
|
||||
|
||||
if year and week:
|
||||
command.extend([year, week])
|
||||
|
||||
result = subprocess.run(
|
||||
command,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"result.html",
|
||||
title="categorize_transactions.py",
|
||||
output=result.stdout + result.stderr
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=5000,
|
||||
debug=True
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue