From 45bccf468baa1cbbde45b162b86987bdb60053cf Mon Sep 17 00:00:00 2001
From: jonnybravo
Date: Thu, 20 Mar 2025 10:25:05 +0100
Subject: [PATCH] first
---
.gitea/workflows/docker.yml | 11 ++++++
Dockerfile | 25 ++++++++++++++
app.py | 46 +++++++++++++++++++++++++
ausgaben.csv | 16 +++++++++
cat_file | 5 +++
docker-compose.yml | 10 ++++++
modify_csv.py | 68 +++++++++++++++++++++++++++++++++++++
read_cat.py | 10 ++++++
requirements.txt | 1 +
templates/add_ausgabe.html | 22 ++++++++++++
templates/base.html | 11 ++++++
templates/index.html | 24 +++++++++++++
templates/output.html | 22 ++++++++++++
13 files changed, 271 insertions(+)
create mode 100644 .gitea/workflows/docker.yml
create mode 100644 Dockerfile
create mode 100644 app.py
create mode 100644 ausgaben.csv
create mode 100644 cat_file
create mode 100644 docker-compose.yml
create mode 100755 modify_csv.py
create mode 100644 read_cat.py
create mode 100644 requirements.txt
create mode 100644 templates/add_ausgabe.html
create mode 100644 templates/base.html
create mode 100644 templates/index.html
create mode 100644 templates/output.html
diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml
new file mode 100644
index 0000000..40d8681
--- /dev/null
+++ b/.gitea/workflows/docker.yml
@@ -0,0 +1,11 @@
+name: start compose
+
+on:
+ - pull_request
+ - push
+
+jobs:
+ start-compose:
+ steps:
+ - name: restart Compose
+ run: docker compose up
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..d1129c0
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,25 @@
+# syntax=docker/dockerfile:1
+
+FROM python:3.14.0a3-alpine3.21
+
+# Set up environment variables for Python
+ENV PYTHONDONTWRITEBYTECODE 1
+ENV PYTHONUNBUFFERED 1
+
+# Create and set the working directory
+WORKDIR /app
+
+# Copy only the requirements file first to leverage Docker caching
+COPY requirements.txt .
+
+# Install dependencies
+RUN pip install --no-cache-dir -r requirements.txt
+
+# Copy the entire application code
+# COPY . .
+
+# Expose the port your application will run on
+EXPOSE 8080
+
+# Specify the command to run on container start
+CMD ["python", "app.py"]
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..83026bb
--- /dev/null
+++ b/app.py
@@ -0,0 +1,46 @@
+from flask import Flask, render_template, request, session
+
+import modify_csv
+import read_cat
+
+app = Flask(__name__)
+app.secret_key = "Start1234!"
+
+
+@app.get("/")
+def index():
+ return render_template(
+ "index.html",
+ sitename="Ausgaben der Familie",
+ data=modify_csv.read_csv_file(),
+ sum_all=modify_csv.sum_all(),
+ )
+
+
+@app.get("/add_ausgabe")
+def add_ausgabe():
+ return render_template(
+ "add_ausgabe.html",
+ url="output",
+ select_id_text="add_value",
+ select_id="add_disc",
+ data=read_cat.read_cat_file(),
+ )
+
+
+@app.post("/output")
+def csv_output():
+ modify_csv.write_csv_file(
+ betrag=request.form["add_value"], select_dist=request.form["add_disc"]
+ )
+ return render_template(
+ "index.html",
+ csv_value_text=request.form["add_value"],
+ csv_value_disc=request.form["add_disc"],
+ data=modify_csv.read_csv_file(),
+ sum_all=modify_csv.sum_all(),
+ )
+
+
+if __name__ == "__main__":
+ app.run(port=5080, host="0.0.0.0", debug=True)
diff --git a/ausgaben.csv b/ausgaben.csv
new file mode 100644
index 0000000..5dce372
--- /dev/null
+++ b/ausgaben.csv
@@ -0,0 +1,16 @@
+datum,ausgaben,beschreibung
+2025-01-09,123,Essen
+2025-01-09,23.34,Essen
+2025-01-09,100,Essen
+2025-01-09,1500,Miete
+2025-01-09,0,Arbeit
+2025-01-14,123.34,Essen
+2025-01-20,2423.3,Essen
+2025-01-20,23,Essen
+2025-01-20,234.45,Arbeit
+2025-03-02,333,Essen
+2025-03-02,2.34,Essen
+2025-03-02,12345.2,Essen
+2025-03-05,10,Essen
+2025-03-05,10,Essen
+2025-03-19,12,Media
diff --git a/cat_file b/cat_file
new file mode 100644
index 0000000..c506ee8
--- /dev/null
+++ b/cat_file
@@ -0,0 +1,5 @@
+Essen
+Baumarkt
+Miete
+Strom
+Media
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..a49c0c6
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,10 @@
+services:
+ python-app:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ ports:
+ - "5080:5080"
+ volumes:
+ - .:/app
+ restart: on-failure:3
diff --git a/modify_csv.py b/modify_csv.py
new file mode 100755
index 0000000..8cd2bea
--- /dev/null
+++ b/modify_csv.py
@@ -0,0 +1,68 @@
+#! /usr/bin/env python3.13
+
+import csv
+import os
+from datetime import date
+
+
+def create_csv_file(csv_path="ausgaben.csv"):
+ if not os.path.exists(csv_path):
+ print(csv_path, "wird angelegt !!")
+ to_write_header = ["datum", "ausgaben", "beschreibung"]
+ with open(csv_path, "w") as wfile:
+ writer = csv.writer(wfile)
+ writer.writerow(to_write_header)
+ return "INFO :", csv_path, "wurde angelegt"
+ else:
+ return "INFO :", csv_path, "existiert bereits"
+
+
+def read_csv_file(csv_file="ausgaben.csv"):
+ if os.path.exists(csv_file):
+ read_csv_file_ausgabe = []
+
+ with open(csv_file, "r") as ocsv:
+ read_csv_full = csv.DictReader(ocsv)
+ for csv_lines in read_csv_full:
+ read_csv_file_ausgabe.append(
+ {
+ "datum": csv_lines["datum"],
+ "ausgabe": csv_lines["ausgaben"],
+ "beschreibung": csv_lines["beschreibung"],
+ }
+ )
+ return read_csv_file_ausgabe
+ else:
+ create_csv_file()
+ read_csv_file()
+
+
+def write_csv_file(
+ csv_file="ausgaben.csv", date_time=date.today(), betrag=float, select_dist="Essen"
+):
+
+ import_list = [date_time, betrag, select_dist]
+ with open(csv_file, "a") as wfile:
+ writer = csv.writer(wfile)
+ writer.writerow(import_list)
+
+
+def sum_all():
+ sum_rech = float(0)
+ for val_csv in read_csv_file():
+ sum_rech = float(sum_rech) + float(val_csv["ausgabe"])
+ return round(sum_rech, 2)
+
+
+if __name__ == "__main__":
+ print(sum_all())
+ # Apply multiple filters
+ # print(create_csv_file())
+ # print(read_csv_file())
+ # for i in read_csv_file():
+ # query_str = i["datum"][:-3]
+ # if query_str == "2025-01":
+# print(i["datum"], " ist in 2025-01")
+# if i["datum"] < date("2025", "01", "01"):
+# print(True)
+# webbrowser.open("file://" + os.path.realpath("ausgabe.html"))
diff --git a/read_cat.py b/read_cat.py
new file mode 100644
index 0000000..d6a11f5
--- /dev/null
+++ b/read_cat.py
@@ -0,0 +1,10 @@
+def read_cat_file(filename="cat_file"):
+ out_list = []
+ with open(filename, "r") as cat:
+ for line in cat:
+ out_list.append(line.rstrip())
+ return out_list
+
+
+if __name__ == "__main__":
+ print(read_cat_file())
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..0da3845
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+flask==2.3.3
diff --git a/templates/add_ausgabe.html b/templates/add_ausgabe.html
new file mode 100644
index 0000000..a101642
--- /dev/null
+++ b/templates/add_ausgabe.html
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+{% block body %}
+
+{% endblock %}
diff --git a/templates/base.html b/templates/base.html
new file mode 100644
index 0000000..48c12ce
--- /dev/null
+++ b/templates/base.html
@@ -0,0 +1,11 @@
+
+
+
+ {{ sitename }}
+
+
+ {{ sitename }}
+ {% block body %}
+ {% endblock %}
+
+
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..fd7bacb
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,24 @@
+{% extends "base.html" %}
+
+ {% block body %}
+
+
Diese Seite zeigt unsere Ausgaben
+ Ausgabe hinzufügen Klick .
+
+
+
+ | Datum |
+ Ausgaben |
+ Beschreibung |
+
+ {% for name in data %}
+
+ | {{ name.get("datum") }} |
+ {{ name.get("ausgabe") }} |
+ {{ name.get("beschreibung") }} |
+
+ {% endfor %}
+
+
Gesamt: {{sum_all}}
+ Nächste Schritte
+ {% endblock %}
diff --git a/templates/output.html b/templates/output.html
new file mode 100644
index 0000000..533ef73
--- /dev/null
+++ b/templates/output.html
@@ -0,0 +1,22 @@
+{% extends "base.html" %}
+
+ {% block body %}
+
+ Ausgabe = {{ csv_value_text }}
Beschreibung = {{csv_value_disc}}
+
+
+
+
+ | Ausgaben |
+ Beschreibung |
+
+ {% for name in data %}
+
+ | {{ name.get("ausgabe") }} |
+ {{ name.get("beschreibung") }} |
+
+ {% endfor %}
+
+
+
Gesamt: {{sum_all}}
+ {% endblock %}