From b51e8ead99b6b5f70fb0b85366540c63cf66d08d Mon Sep 17 00:00:00 2001 From: Alexander Malzkuhn Date: Mon, 7 Apr 2025 13:41:32 +0200 Subject: [PATCH] Split + JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aufteilung auf unterschiedliche Dateien Beginn mit JSON Imports für settings. --- __pycache__/jsonhandler.cpython-38.pyc | Bin 0 -> 455 bytes __pycache__/timestamping.cpython-38.pyc | Bin 0 -> 1757 bytes __pycache__/users.cpython-38.pyc | Bin 0 -> 1045 bytes __pycache__/zeiterfassung.cpython-38.pyc | Bin 0 -> 1377 bytes jsonhandler.py | 24 +++++++ timestamping.py | 71 +++++++++++++++++++ users.py | 30 ++++++++ users/testuser/2025-4.txt | 2 + users/testuser/settings.json | 5 ++ zeiterfassung.py | 85 +---------------------- 10 files changed, 135 insertions(+), 82 deletions(-) create mode 100644 __pycache__/jsonhandler.cpython-38.pyc create mode 100644 __pycache__/timestamping.cpython-38.pyc create mode 100644 __pycache__/users.cpython-38.pyc create mode 100644 __pycache__/zeiterfassung.cpython-38.pyc create mode 100644 jsonhandler.py create mode 100644 timestamping.py create mode 100644 users.py create mode 100644 users/testuser/settings.json diff --git a/__pycache__/jsonhandler.cpython-38.pyc b/__pycache__/jsonhandler.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2160e1aa6e807b04647de22e892b3ba3b8b8b9be GIT binary patch literal 455 zcmYjNJx{|h5WREKHk1Y-!7pG716g1LgamWNr$AY%2)iHP#Fgy`irNWw{sN5r1AYio zRwiaPChkC>o^;Reoz8d9K8xcvP`tf<4sHw|7WH^Ca$3EGuYwr{jlmei6{-jB+G`>kA(h5rbMEl}=L zx-|k1Q@F>+5>tG}nK*|nID%uifT^Hm*iC{uG-FlP;gvIl+T@aIQGcXWnHMTs z;Chc`9m?G2FJSo#zIM`~DO8$kb(@#uEgz}@9#M)?72w*qK&JSQdw(p=!6ILbwhJRG Rt#(_aTtpCw2s_w`z5x!xZRY?0 literal 0 HcmV?d00001 diff --git a/__pycache__/timestamping.cpython-38.pyc b/__pycache__/timestamping.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..701c06a629e468d147f06e26458a8d5fe34726df GIT binary patch literal 1757 zcmZ8h&u<$=6rLZu_S$vaB(w=F6|xXPxDqz13I~KLB+?2AVF96PY6*o^X6$Tj@4B<& zrnS}=%oV{MRZ0XLxO3*he=%21IU_Ed_};|WP1l+q@6DU%dGGt)yT7(pW%z#m{qO!i zWyby@;l)ot_y{B4#iW?xL)JZCd6#=xbcGU1e#g2}1uDcEsFEsU4OOHnSWBv^E@3Sz zzQ>xiGk9X1Lr%-$3$Ru&KE}umCd({8;iqiQXMB3oiUR*U7e8#xL?KRO!GB^(JQt^& zvj^-w_67Tr?PHg|A21sXs%FR;{cQNCbW$$ZDW6H~qe3dY@q2-jN&(-TJ!GlaM?82} z*l|2|y!us>yGTDxa(j>snpG#0)VjbXBkh80tWy^ro5X6jaW5I_PG;|AlT_U`CNoZC zxeLazJ#uB0m^8+fXcP}LgxsyiW878;9{=L&a%0{{!5B1YH#bJ9l8%#zzwYvTJGkcV!?XJetOfSy!N!o8OeI{wYHGXF5 za1v39*D*0s69VIPUKcf9=l=8pDiTJ-4v)$=*i3I*wm_mWelHl>Alb za!M5Al%0q-kehXGu0eAlJ5(7oe0FYOL%AWo7F_XxFxM?t$O~ub6=>uZ7!2)AidKaf z#JN((2Qr~IeyR~c<1QX;{`{q{&&YRoEuQ3k&_$2NdT6_Auvv*s;a_F8VTrvDl%D@` zgqIih52h0kFI8{CCa+;)Ji@QaYdjF%0D11!LP5tUzJ~<%_K%((GIL6 zO3cMB`})=_EJ7u>nF^2sffVc)!AVevBD{vemoF;@_U&-fYf$6Uwc*tEW*T05iG z&cnveCm-y5HkFNc8q?74n`KWibCoPZ6C?X(i}t1SYWBHz8;4o?L>s%JQM0t-ogqxR zQL@-Q#FGC%+7oD= zk?&$Ny+M8S5kDb7kcv}|L}R9E-SZuiIv{oBMg57+RJK~JX6R&Yjf)hD(09JIp2!6$V><107%aFnUZP~VYI`I;p1NEYEd=1`X5V4eOv$l literal 0 HcmV?d00001 diff --git a/__pycache__/users.cpython-38.pyc b/__pycache__/users.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f0b193f21de8a047fef0ea601b3eaf41b4f7e1ed GIT binary patch literal 1045 zcmZuwOK%fF47O)ylWj;)d8P=|Bhn&~aN|-{Nc4yzq>9T*C|WYpbjv=%%tSO*dTJ%g zk$=z}dqv{U%#{;oZaradikb?%8hh-qXY9}3cb!fPh`#>#J^n5LezLMkWP?|<>>FYV z6y}gDB_>$wA`v7-9uzW>$Y%lV!z84=RN*Nk4b@Ohl1&w#Fvo>hppkR@CO*ksxPVxCQCTl1soVEqW>sdqJgBlV z7GCsTcvKhY*T||zt}-*j8D75Z?^lKHr@1~%ORB8DQ+=Ekx^%k#cINi0vY+V8QQfJv z({kKr3~X;Q^R2Bsvu;!slkE;?+91{d0T1D5lTU_A&#k-~rMcbiUAxD^gyig->_+L3 z-ex_lBkHuwEixFs*SD@OV=v2D18$(XL-Gc2e-VGpZUbTt95Q4JI0zW+6-0TC^O*J{Hmni@T;p(`Hmif<~54N75 zXjnfw94-^OnVNY-L0pC9x@1?PuttXBBW2Wu^mJ*YW@MSM(08R literal 0 HcmV?d00001 diff --git a/__pycache__/zeiterfassung.cpython-38.pyc b/__pycache__/zeiterfassung.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bcf0a87bf1f9a2eec8744da788fe86f176e63a19 GIT binary patch literal 1377 zcmb7EL2n#26t=xHyR);qNwq?4sVG>81KUHE_80+eMJWQL2oVa>NY!W(zs!tw#xu1& zNxRydmLC9D{sBJ#i9>Gr5lBA5DQ9ju@jSa51t}b`Wk0_+e((GIo;@!{qmW?x`M1B* zKYT*|a?16_Po*#dwt)s?a+zv7iXbcCa5h zk4^J%(Zlf>4*fkP#1KOTy+aH$oh8a8rDzjuEz#EMUMoH03x7$M^pq@!=pwh@P1p36 zMD#F1;Ji<%Aq(7rUVRam(5;v38F~4^DMKu_V4~~xiN3>J&;@%NwH5BG4C99wqhkhU zxS+;cAin6{C2r4}$-qhZ3*rxF>?f+ex`Dy}NB$F$M=dfDTV`|<`Z_mTH+@4!0cLI6 zaT5gVbZhUD^5#R#@()lPX272}a%S>Ma$OY#Pa2)V(fL`X3_k%SKt7%i9`5pe17!_` zZ0@7yqbvRV>;Ma$A7+Lpat?V4a{kU2Z~&6;=fJEO0zTBwtlUUfgRSWN>x(E zGAY4!v{80@V>))Jsif_=jeaic#@MjPwTV~HBh-f~uT7np%!bZ%R22f0^_3%KI|WF4 zE2(RcA~t!6$wg+JYO-lL51MQIh;&98@y`J)e#9Ch$CQW zZo`ud>()~Fl_*!%%g58KDq)%w@EVT~YWl32HJDff({J9Gtdi4zJ>zMc!p)=Jsoz+y zOmcY}Lupr4Lf@i6+lMTmV_c2t`?$JGL+s len(out_times): + out_times.append("") + for i in range(0, len(in_times)): + print(convert_timestamp(in_times[i], "%d.%m.%Y %H:%M") + " - " + convert_timestamp(out_times[i], "%H:%M")) + + +# Timestamp konvertieren +def convert_timestamp(timestamp, format): + try: + return str(datetime.datetime.fromtimestamp(int(timestamp)).strftime(format)) + except: + return ("...") \ No newline at end of file diff --git a/users.py b/users.py new file mode 100644 index 0000000..c7f5880 --- /dev/null +++ b/users.py @@ -0,0 +1,30 @@ +# Zeiterfassung +# Benutzerfunktionen + +import os +import time +import datetime + +from zeiterfassung import userfolder +from zeiterfassung import settingsfolder + +# Benutzer anhand Verzeichnisse auflisten +def list_users(directory): + users = [d for d in os.listdir(directory) if os.path.isdir(os.path.join(directory, d))] + return users + +def determine_filename(user, type="stamping"): + if type == "stamping": + year = str(datetime.datetime.now().year) + month = str(datetime.datetime.now().month) + completepath = scriptpath() + "/" + userfolder +"/" + user + "/" + year + "-" + month + ".txt" + return completepath + elif type == "settings": + settings_filename = "setting.json" + completepath = scriptpath() + "/" + userfolder +"/" + user + "/" settings_filename + return completepath + +# Installationsverzeichnis bestimmen +def scriptpath(): + + return os.path.dirname(os.path.abspath(__file__)) \ No newline at end of file diff --git a/users/testuser/2025-4.txt b/users/testuser/2025-4.txt index b06d023..1fb89f3 100644 --- a/users/testuser/2025-4.txt +++ b/users/testuser/2025-4.txt @@ -5,3 +5,5 @@ 1743966047 1743966049 1743967346 +1744024713 +1744024974 diff --git a/users/testuser/settings.json b/users/testuser/settings.json new file mode 100644 index 0000000..b6c41f6 --- /dev/null +++ b/users/testuser/settings.json @@ -0,0 +1,5 @@ +{ + "username": "testuser", + "name": "Der Tester", + "password": "123456789" +} diff --git a/zeiterfassung.py b/zeiterfassung.py index 7f45a74..486ae74 100644 --- a/zeiterfassung.py +++ b/zeiterfassung.py @@ -6,6 +6,9 @@ import time import datetime import os +from timestamping import * +from users import * +from jsonhandler import * # Statische Definitionen # Pfade: @@ -16,88 +19,6 @@ program_version = "0.0.0" # Funktionen -# Zeitstempel schreiben -def append_timestamp(filename): - # Hole den aktuellen Timestamp in Epoch-Zeit - timestamp = int(time.time()) - - try: - # Öffne die Datei im Anhang-Modus ('a') - with open(filename, 'a') as file: - # Schreibe den Timestamp in die Datei und füge einen Zeilenumbruch hinzu - file.write(f"{timestamp}\n") - except FileNotFoundError: - # Fehlende Verzeichnisse anlegen - folder_path = os.path.dirname(filename) - os.makedirs(folder_path, exist_ok=True) - append_timestamp(filename) - -# Anzahl der Zeilen zählen -def len_timestamps(filename): - try: - # Öffne die Datei im Lese-Modus ('r') - with open(filename, 'r') as file: - # Zähle die Zeilen - lines = file.readlines() - return len(lines) - except FileNotFoundError: - print(f"Die Datei {filename} wurde nicht gefunden.") - return 0 - -# Stempelzustand auslesen -def stempel_zustand(filename): - lines = len_timestamps(filename) - if lines == 0: - print(f"Keine Einträge") - elif lines % 2 == 0: - return("ausgestempelt") - else: - return("eingestempelt") - -# Stempelübersicht zusammenstellen -def overview(filename): - - # Öffne die Datei im Lese-Modus ('r') - with open(filename, 'r') as file: - lines = file.readlines() - - in_times = [] - out_times = [] - - for i in range(0, len(lines)): - if (i + 1) % 2 == 0: - out_times.append(lines[i]) - else: - in_times.append(lines[i]) - if len(in_times) > len(out_times): - out_times.append("") - for i in range(0, len(in_times)): - print(convert_timestamp(in_times[i], "%d.%m.%Y %H:%M") + " - " + convert_timestamp(out_times[i], "%H:%M")) - - -# Timestamp konvertieren -def convert_timestamp(timestamp, format): - try: - return str(datetime.datetime.fromtimestamp(int(timestamp)).strftime(format)) - except: - return ("...") - -# Pfade bestimmen -def scriptpath(): - return os.path.dirname(os.path.abspath(__file__)) - -def determine_filename(user): - year = str(datetime.datetime.now().year) - month = str(datetime.datetime.now().month) - completepath = scriptpath() + "/" + userfolder +"/" + user + "/" + year + "-" + month + ".txt" - return completepath - -# Benutzer anhand Verzeichnisse auflisten -def list_users(directory): - users = [d for d in os.listdir(directory) if os.path.isdir(os.path.join(directory, d))] - return users - - # Hauptfunktion def main(): print(program_name + " " + str(program_version))