From d6549a95faafb1b6773d17ffca775df9da8ac849 Mon Sep 17 00:00:00 2001 From: Markus Zimmerberger Date: Tue, 22 Apr 2025 16:05:37 +0200 Subject: [PATCH] Add GEMS-Export --- .gitignore | 1 + .vscode/launch.json | 15 ---- ...GEMS_2025-04 LNW Markus Zimmerberger.xlsx# | 1 + app/GEMS export timesheets.py | 76 +++++++++++++++++++ ...imesheets.py => MA01 export timesheets.py} | 4 +- app/codeium.py | 8 ++ app/config.yaml | 9 ++- 7 files changed, 95 insertions(+), 19 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 .~lock.GEMS_2025-04 LNW Markus Zimmerberger.xlsx# create mode 100644 app/GEMS export timesheets.py rename app/{export timesheets.py => MA01 export timesheets.py} (97%) create mode 100644 app/codeium.py diff --git a/.gitignore b/.gitignore index ee5e1f0..1fa599a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.csv *.pdf +*.xlsx \env \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 6b76b4f..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python Debugger: Current File", - "type": "debugpy", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file diff --git a/.~lock.GEMS_2025-04 LNW Markus Zimmerberger.xlsx# b/.~lock.GEMS_2025-04 LNW Markus Zimmerberger.xlsx# new file mode 100644 index 0000000..9e5de00 --- /dev/null +++ b/.~lock.GEMS_2025-04 LNW Markus Zimmerberger.xlsx# @@ -0,0 +1 @@ +,markus,Banjul,22.04.2025 16:01,file:///home/markus/.config/libreoffice/4; \ No newline at end of file diff --git a/app/GEMS export timesheets.py b/app/GEMS export timesheets.py new file mode 100644 index 0000000..cb059a8 --- /dev/null +++ b/app/GEMS export timesheets.py @@ -0,0 +1,76 @@ +from dataclasses import dataclass +import gspread +import csv +import locale +import datetime +import yaml +import os +from pathlib import Path + + +#TODO: Upload automatically! + +@dataclass +class Export: # all necessary fields for ELSAP-importfiles + sum_col: str + desc_col: str + +def export_timesheet(csvexport_filename, ex: Export): + if not hasattr(export_timesheet, "row"): + export_timesheet.row = 4 + with open(f"{csvexport_filename}.csv", 'w') as file: + writer = csv.writer(file, delimiter=';', lineterminator="\n") + + period = datetime.datetime.strptime(cfg['worksheet_name'], "%B %Y").date().replace(day=1) + writer.writerow(["","","","Current Period",f"{period.strftime('%d.%m.%Y')}"]) + writer.writerow("") + writer.writerow(["Name","PersNr","CostCenter","Day","Date","Status","WBS element","Description","PARMA","Task Name","Activity Code","ActType","Profit center","Quantity","Unit","Project description","Customer name","Statistical key figure","A/AType","Description A/A type","AI","Activity","Short text"]) + + # iterate + for time_entry in list_of_dicts: + date_str_de_de = time_entry.get("date") + if date_str_de_de not in ["","Wochensumme","Summe (kumuliert)"]: + datetime_object = datetime.datetime.strptime(date_str_de_de, '%a., %d. %B %Y') + writer.writerow([cfg['name'],cfg['pers_nr'],"",f"=WEEKDAY(E{export_timesheet.row})",datetime_object.strftime('%d.%m.%Y'),"",cfg['WBS_element'],cfg['WBS_desc'],"","","","","",time_entry.get(ex.sum_col),"Hours",time_entry.get(ex.desc_col)]) + export_timesheet.row += 1 + + # Check if the file size is small (indicating only the header) + file_path = f"{csvexport_filename}.csv" + + # Use os.path.getsize to get the file size + if os.path.getsize(file_path) <= 190: # Adjust this size threshold based on your expected header size + os.remove(file_path) + print(f"File {file_path} was deleted because it only contained the header.") + else: + print(f"File {file_path} contains data and was not deleted.") + +# Set locale to German (Germany) +locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8') +#locale.setlocale(locale.LC_ALL, 'de_AT.UTF-8') + +with open("./app/config.yaml", encoding='utf8') as f: + cfg = yaml.load(f, Loader=yaml.FullLoader) + +home = Path.home() +gc = gspread.service_account(home / "service_account.json") +sh = gc.open(cfg['spreadsheet_name']) +worksheet = sh.worksheet(cfg['worksheet_name']) +week = cfg['week'] # 10, 11, 12 or None + +username = cfg['username'] +name = cfg['name'] +ansprechpartner_username = cfg['ansprechpartner_username'] +ansprechpartner_name = cfg['ansprechpartner_name'] + +# read the whole sheet +list_of_dicts = worksheet.get_all_records(numericise_ignore=['all']) + +for key in ["gems"]: + # extract period out of sheet-name + period = datetime.datetime.strptime(cfg['worksheet_name'], "%B %Y").date().replace(day=1) + csvexport_filename = f"GEMS_{period.strftime('%Y-%m')} LNW {cfg['name']}" + + ex1 = Export(sum_col=f"sum_{key}", + desc_col=f"desc_{key}") + + export_timesheet(csvexport_filename=csvexport_filename, ex=ex1) \ No newline at end of file diff --git a/app/export timesheets.py b/app/MA01 export timesheets.py similarity index 97% rename from app/export timesheets.py rename to app/MA01 export timesheets.py index 47bf18a..fb33c88 100644 --- a/app/export timesheets.py +++ b/app/MA01 export timesheets.py @@ -53,7 +53,9 @@ def export_timesheet(csvexport_filename, ex: Export): else: print(f"File {file_path} contains data and was not deleted.") -locale.setlocale(locale.LC_ALL, 'de_AT.UTF-8') +# Set locale to German (Germany) +locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8') +#locale.setlocale(locale.LC_ALL, 'de_AT.UTF-8') with open("./app/config.yaml", encoding='utf8') as f: cfg = yaml.load(f, Loader=yaml.FullLoader) diff --git a/app/codeium.py b/app/codeium.py new file mode 100644 index 0000000..3484d9b --- /dev/null +++ b/app/codeium.py @@ -0,0 +1,8 @@ +# fibonacci +def fib(n): + if n <= 1: + return n + else: + return fib(n-1) + fib(n-2) + +print(fib(1)) \ No newline at end of file diff --git a/app/config.yaml b/app/config.yaml index 00d6065..7d88ea4 100644 --- a/app/config.yaml +++ b/app/config.yaml @@ -5,9 +5,12 @@ 'spread': 1.0}, 'visualize_params': {'median_threshold': 6}, 'spreadsheet_name': 'Zeiterfassung alle Projekte', - 'worksheet_name': 'Dezember 2024', - 'week': [51], + 'worksheet_name': 'April 2025', + 'week': [10,11,12,13,14], 'name': 'Markus Zimmerberger', 'username': 'ZIM9003', 'ansprechpartner_username': 'GRM0003', - 'ansprechpartner_name': 'Marlene Griesser'} \ No newline at end of file + 'ansprechpartner_name': 'Marlene Griesser', + 'WBS_element': 'AT72400401010', + 'WBS_desc': 'GEMS MVZV Core FP', + 'pers_nr': '90000002'} \ No newline at end of file