Initial
This commit is contained in:
commit
c617c886a1
7
users/testuser/2025-4.txt
Normal file
7
users/testuser/2025-4.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
1743965819
|
||||||
|
1743965909
|
||||||
|
1743966022
|
||||||
|
1743966045
|
||||||
|
1743966047
|
||||||
|
1743966049
|
||||||
|
1743967346
|
2
users/testuser2/2025-4.txt
Normal file
2
users/testuser2/2025-4.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1743966330
|
||||||
|
1743966416
|
113
zeiterfassung.py
Normal file
113
zeiterfassung.py
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
# Zeiterfassung
|
||||||
|
|
||||||
|
# Bibliotheksimports
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Statische Definitionen
|
||||||
|
# Pfade:
|
||||||
|
userfolder = "users"
|
||||||
|
settingsfolder = "settings"
|
||||||
|
program_name = "Zeiterfassung"
|
||||||
|
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("in")
|
||||||
|
else:
|
||||||
|
return("out")
|
||||||
|
|
||||||
|
# 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)-1):
|
||||||
|
if (i + 1) % 2 == 0:
|
||||||
|
out_times.append(lines[i])
|
||||||
|
else:
|
||||||
|
in_times.append(lines[i])
|
||||||
|
for i in range(0, len(in_times) - 1):
|
||||||
|
print(str(in_times[i]) + " - " + str(out_times[i]))
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
print("Welche Funktion soll ausgeführt werden?")
|
||||||
|
print("1: Stempeln")
|
||||||
|
print("2: Stempelübersicht anzeigen")
|
||||||
|
question = int(input("Geben Sie Ihre Antwort ein: "))
|
||||||
|
|
||||||
|
if question == 1:
|
||||||
|
which_user = input("Für welchen User soll gestempelt werden? ")
|
||||||
|
append_timestamp(determine_filename(which_user))
|
||||||
|
print("Stempeleintrag vorgenommen")
|
||||||
|
elif question == 2:
|
||||||
|
which_user = input("Für welchen User sollen die Stempelzeiten angezeigt werden?" )
|
||||||
|
print("Zustand: " + stempel_zustand(determine_filename(which_user)))
|
||||||
|
overview(determine_filename(which_user))
|
||||||
|
else:
|
||||||
|
print("Keine Eingabe erkannt.")
|
||||||
|
|
||||||
|
|
||||||
|
# Programmstart
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user