From 241552fb6db3d3cee3547d637994277a10f86425 Mon Sep 17 00:00:00 2001 From: elpatron Date: Tue, 22 Jul 2025 16:36:22 +0200 Subject: [PATCH] Initialer Commit: Datumsrechner-App mit allen Funktionen, modernem Design und Template-Trennung --- .gitignore | 29 ++++ README.md | 24 +++ app.py | 105 ++++++++++++ favicon.ico | Bin 0 -> 4286 bytes favicon.png | Bin 0 -> 841 bytes favicon.svg | 6 + idea.txt | 8 + logo.svg | 8 + requirements.txt | 2 + templates/index.html | 374 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 556 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app.py create mode 100644 favicon.ico create mode 100644 favicon.png create mode 100644 favicon.svg create mode 100644 idea.txt create mode 100644 logo.svg create mode 100644 requirements.txt create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8021d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd + +# Virtualenv +.venv/ +venv/ +ENV/ + +# VS Code +.vscode/ + +# Sonstige +.DS_Store +Thumbs.db + +# Logdateien +*.log + +# Test-/Coverage-Dateien +htmlcov/ +.coverage +.tox/ +.pytest_cache/ + +# Betriebssystem +*.swp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..074aca0 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Datumsberechnungen Web-App + +Diese kleine Python-Webanwendung ermöglicht folgende Datumsberechnungen: + +- Anzahl der Tage zwischen zwei Daten +- Anzahl der Werktage zwischen zwei Daten +- Anzeige des Wochentags eines Datums + +## Installation + +1. Python 3.8+ installieren +2. Abhängigkeiten installieren: + + ``` + pip install -r requirements.txt + ``` + +## Starten der App + +``` +python app.py +``` + +Die App ist dann unter http://localhost:5000 erreichbar. \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..49298fe --- /dev/null +++ b/app.py @@ -0,0 +1,105 @@ +from flask import Flask, render_template, request +from datetime import datetime, timedelta +import numpy as np + +app = Flask(__name__) + +# HTML-Template wird jetzt aus templates/index.html geladen + +WOCHENTAGE = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"] + +@app.route('/', methods=['GET', 'POST']) +def index(): + tage = werktage = wochentag = datumsrechnung = werktagsrechnung = kw_berechnen = kw_datum = None + active_idx = 0 + if request.method == 'POST': + action = request.form.get('action') + if action == 'tage': + active_idx = 0 + start = request.form.get('start1') + end = request.form.get('end1') + try: + d1 = datetime.strptime(start, '%Y-%m-%d') + d2 = datetime.strptime(end, '%Y-%m-%d') + tage = abs((d2 - d1).days) + except Exception: + tage = 'Ungültige Eingabe' + elif action == 'werktage': + active_idx = 1 + start = request.form.get('start2') + end = request.form.get('end2') + try: + d1 = datetime.strptime(start, '%Y-%m-%d') + d2 = datetime.strptime(end, '%Y-%m-%d') + if d1 > d2: + d1, d2 = d2, d1 + werktage = np.busday_count(d1.date(), (d2 + timedelta(days=1)).date()) + except Exception: + werktage = 'Ungültige Eingabe' + elif action == 'wochentag': + active_idx = 2 + datum = request.form.get('datum3') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + wochentag = WOCHENTAGE[d.weekday()] + except Exception: + wochentag = 'Ungültige Eingabe' + elif action == 'datumsrechnung': + active_idx = 3 + datum = request.form.get('datum4') + tage_input = request.form.get('tage4') + richtung = request.form.get('richtung4') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + tage_int = int(tage_input) + if richtung == 'add': + result = d + timedelta(days=tage_int) + else: + result = d - timedelta(days=tage_int) + datumsrechnung = result.strftime('%d.%m.%Y') + except Exception: + datumsrechnung = 'Ungültige Eingabe' + elif action == 'werktagsrechnung': + active_idx = 4 + datum = request.form.get('datum5') + tage_input = request.form.get('tage5') + richtung = request.form.get('richtung5') + try: + d = datetime.strptime(datum, '%Y-%m-%d').date() + tage_int = int(tage_input) + if richtung == 'add': + result = np.busday_offset(d, tage_int, roll='forward') + else: + result = np.busday_offset(d, -tage_int, roll='backward') + werktagsrechnung = np.datetime_as_string(result, unit='D') + # Formatierung auf deutsch + dt = datetime.strptime(werktagsrechnung, '%Y-%m-%d') + werktagsrechnung = dt.strftime('%d.%m.%Y') + except Exception: + werktagsrechnung = 'Ungültige Eingabe' + elif action == 'kw_berechnen': + active_idx = 5 + datum = request.form.get('datum6') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + kw = d.isocalendar().week + kw_berechnen = f"KW {kw} ({d.year})" + except Exception: + kw_berechnen = 'Ungültige Eingabe' + elif action == 'kw_datum': + active_idx = 6 + jahr = request.form.get('jahr7') + kw = request.form.get('kw7') + try: + jahr = int(jahr) + kw = int(kw) + # Montag der KW + start = datetime.fromisocalendar(jahr, kw, 1) + end = datetime.fromisocalendar(jahr, kw, 7) + kw_datum = f"{start.strftime('%d.%m.%Y')} bis {end.strftime('%d.%m.%Y')}" + except Exception: + kw_datum = 'Ungültige Eingabe' + return render_template('index.html', tage=tage, werktage=werktage, wochentag=wochentag, datumsrechnung=datumsrechnung, werktagsrechnung=werktagsrechnung, kw_berechnen=kw_berechnen, kw_datum=kw_datum, active_idx=active_idx) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9739ecd80b4efb9e332ff36d7b87a3c523c2923c GIT binary patch literal 4286 zcmeI0OGs2v7{_nxHbKy`#zn71Pz!NmU{d&~M(D9<6%|TiYEU3$Vo}*9YhzRkE1_^C z$k8aubjF!r#-V7FBt%b((Q)46_0H?g{ddlp?rn6=kmfvEc!vL+x!*b8_dAb|@4^Ve zD)Q0k1o|x))(FBnK@heO5tC3xMD47Rv9+s{N*V+KYLnxLj13}mry2hCeektbWLIs~ z2;4XZ>18*Ru&7d5FV9Reru)Q3xkHl2zJ#Mj32t)2>;~+T)wBN7-H`gNW(qL(%h3yc+Zq_88pxRmuk|+yr)Z$@H*$^ z=yDzsff>-4>ba{u%>f=?G+bQ{j_WJ-bu5}MJ-^G1!Hh}*iZlz5dZD&N&<)x72}&%Y zn$mjd)q||?DTkgPtyQ!|-&=pj-2~669f-agN@G()uJ{SR3-o@KsD$9n~A@$cjF?w{r!%Ln@a z)P~qrE&kpr{lCPM(jq!CTv9Z zf0Pa3*N@rxsLa$p)BaQE)I#Er+SL>c8c`I9!4c-Pd7lJh(* zxVRXCvAihbJYN1pLw@G#dSl7xNALc}$N-705&##ysGZUHq$UcHtD4@l0IYu!}Y>SoZNY9S>q{eobG3T6Ar>yh^JOTB8 IfI{`Z0K(^b literal 0 HcmV?d00001 diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..7845ed67390ec52c2d693c9b8d03367e2d542713 GIT binary patch literal 841 zcmV-P1GfB$P)9q7C zZM8Ij$|q_pQ6m9AK^B@|1rrP#S1#0GT$o5=bkz+phPW{%R(CF>V&X=42#HSHALa9ZBprTY$YF44{-l?m%zKH28&+PTp z7Civ$vG#WD#&V(q8VhYYJ7Sf@P{tt4FvjvtXHRJm@_&p9 z3HEMh&NnExZNVEaFA6Z@N;-NYV^awkfucg(bwgLc=TN)s=|hT^o4y~jX`@A&qQ)A9 zggqRkUHy^THh0g*RKqv7`>Zyv)#kNz23LFXENZG%$ecj0kxI5d3B4YQ2E(a&6;Hs} zRN``zs@QkOW>c{`rUw`bO6T5cx8cEhmU&~T7*^o5f$<9xj`&5U`Uh!CiiC>#T=3S+qlvljS1 zow#_{j{pjk==KGTY&ma8psa`t-81kU0)S&x-1|FvAw)}zSi#D-i&VhnUni*;fm*r3 zWz=G$c73{8k94~DKHD%;l%g-$guu zwBQ(m7*io0ai+QYLiEv_a8~SpLRk^Pbr$(<%o!*4bGYTGVyB7ZgT2B`8fz4o=g`A8 z?e3DS8zM7`jpV@{XtJKmAL000000NkvXXu0mjfQ9*oh literal 0 HcmV?d00001 diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 0000000..34ce014 --- /dev/null +++ b/favicon.svg @@ -0,0 +1,6 @@ + + + + + 15 + \ No newline at end of file diff --git a/idea.txt b/idea.txt new file mode 100644 index 0000000..27f5bb3 --- /dev/null +++ b/idea.txt @@ -0,0 +1,8 @@ +erstelle eine python web app, die verschiedene datumsberechnungen durchführt: +- Berechnung der Anzahl der Tage zwischen zwei Daten +- Berechnung der Anzahl der Werktage zwischen zwei Daten +- Anzeige des Wochentags eines Datums + +Beachte: +- Virtual Environment unter ./.venv +- Wir entwickeln unter Windows \ No newline at end of file diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..d961a14 --- /dev/null +++ b/logo.svg @@ -0,0 +1,8 @@ + + + + + 15 + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ec642b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.0.3 +numpy==1.26.4 \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8529d9b --- /dev/null +++ b/templates/index.html @@ -0,0 +1,374 @@ + + + + + Elpatrons Datumsrechner + + + + + + +
+

Datumsberechnungen

+
+
+ +
+
+ + + +
+ {% if tage is not none %} +
Anzahl der Tage: {{ tage }}
+ {% endif %} +
+
+
+ +
+
+ + + +
+ {% if werktage is not none %} +
Anzahl der Werktage: {{ werktage }}
+ {% endif %} +
+
+
+ +
+
+ + +
+ {% if wochentag is not none %} +
Wochentag: {{ wochentag }}
+ {% endif %} +
+
+
+ +
+
+ + + + + + + +
+ {% if datumsrechnung is not none %} +
Ergebnis: {{ datumsrechnung }}
+ {% endif %} +
+
+
+ +
+
+ + + + + + + +
+ {% if werktagsrechnung is not none %} +
Ergebnis: {{ werktagsrechnung }}
+ {% endif %} +
+
+
+ +
+
+ + +
+ {% if kw_berechnen is not none %} +
Kalenderwoche: {{ kw_berechnen }}
+ {% endif %} +
+
+
+ +
+
+ + + +
+ {% if kw_datum is not none %} +
{{ kw_datum }}
+ {% endif %} +
+
+
+
+ + \ No newline at end of file