Split + JSON
Aufteilung auf unterschiedliche Dateien Beginn mit JSON Imports für settings.
This commit is contained in:
parent
b777f4ad4f
commit
b51e8ead99
BIN
__pycache__/jsonhandler.cpython-38.pyc
Normal file
BIN
__pycache__/jsonhandler.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/timestamping.cpython-38.pyc
Normal file
BIN
__pycache__/timestamping.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/users.cpython-38.pyc
Normal file
BIN
__pycache__/users.cpython-38.pyc
Normal file
Binary file not shown.
BIN
__pycache__/zeiterfassung.cpython-38.pyc
Normal file
BIN
__pycache__/zeiterfassung.cpython-38.pyc
Normal file
Binary file not shown.
24
jsonhandler.py
Normal file
24
jsonhandler.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Zeiterfassung
|
||||||
|
|
||||||
|
# JSON Handling
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from users import *
|
||||||
|
from zeiterfassung import userfolder
|
||||||
|
from zeiterfassung import settingsfolder
|
||||||
|
|
||||||
|
# Datenstrutur:
|
||||||
|
|
||||||
|
# user: Benutzername
|
||||||
|
# name: Vollständiger Name
|
||||||
|
# password: gehashtes Passwort
|
||||||
|
|
||||||
|
def load_settings(filename):
|
||||||
|
|
||||||
|
with open(filename) as json_file:
|
||||||
|
data = json.load(json_file)
|
||||||
|
|
||||||
|
return data
|
71
timestamping.py
Normal file
71
timestamping.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Funktionen bzgl. Timestamps
|
||||||
|
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
|
# 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 ("...")
|
30
users.py
Normal file
30
users.py
Normal file
@ -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__))
|
@ -5,3 +5,5 @@
|
|||||||
1743966047
|
1743966047
|
||||||
1743966049
|
1743966049
|
||||||
1743967346
|
1743967346
|
||||||
|
1744024713
|
||||||
|
1744024974
|
||||||
|
5
users/testuser/settings.json
Normal file
5
users/testuser/settings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"username": "testuser",
|
||||||
|
"name": "Der Tester",
|
||||||
|
"password": "123456789"
|
||||||
|
}
|
@ -6,6 +6,9 @@
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
from timestamping import *
|
||||||
|
from users import *
|
||||||
|
from jsonhandler import *
|
||||||
|
|
||||||
# Statische Definitionen
|
# Statische Definitionen
|
||||||
# Pfade:
|
# Pfade:
|
||||||
@ -16,88 +19,6 @@ program_version = "0.0.0"
|
|||||||
|
|
||||||
# Funktionen
|
# 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
|
# Hauptfunktion
|
||||||
def main():
|
def main():
|
||||||
print(program_name + " " + str(program_version))
|
print(program_name + " " + str(program_version))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user