Add GEMS-Export
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
*.csv
|
*.csv
|
||||||
*.pdf
|
*.pdf
|
||||||
|
*.xlsx
|
||||||
\env
|
\env
|
||||||
Vendored
-15
@@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
,markus,Banjul,22.04.2025 16:01,file:///home/markus/.config/libreoffice/4;
|
||||||
@@ -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)
|
||||||
@@ -53,7 +53,9 @@ def export_timesheet(csvexport_filename, ex: Export):
|
|||||||
else:
|
else:
|
||||||
print(f"File {file_path} contains data and was not deleted.")
|
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:
|
with open("./app/config.yaml", encoding='utf8') as f:
|
||||||
cfg = yaml.load(f, Loader=yaml.FullLoader)
|
cfg = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# fibonacci
|
||||||
|
def fib(n):
|
||||||
|
if n <= 1:
|
||||||
|
return n
|
||||||
|
else:
|
||||||
|
return fib(n-1) + fib(n-2)
|
||||||
|
|
||||||
|
print(fib(1))
|
||||||
+6
-3
@@ -5,9 +5,12 @@
|
|||||||
'spread': 1.0},
|
'spread': 1.0},
|
||||||
'visualize_params': {'median_threshold': 6},
|
'visualize_params': {'median_threshold': 6},
|
||||||
'spreadsheet_name': 'Zeiterfassung alle Projekte',
|
'spreadsheet_name': 'Zeiterfassung alle Projekte',
|
||||||
'worksheet_name': 'Dezember 2024',
|
'worksheet_name': 'April 2025',
|
||||||
'week': [51],
|
'week': [10,11,12,13,14],
|
||||||
'name': 'Markus Zimmerberger',
|
'name': 'Markus Zimmerberger',
|
||||||
'username': 'ZIM9003',
|
'username': 'ZIM9003',
|
||||||
'ansprechpartner_username': 'GRM0003',
|
'ansprechpartner_username': 'GRM0003',
|
||||||
'ansprechpartner_name': 'Marlene Griesser'}
|
'ansprechpartner_name': 'Marlene Griesser',
|
||||||
|
'WBS_element': 'AT72400401010',
|
||||||
|
'WBS_desc': 'GEMS MVZV Core FP',
|
||||||
|
'pers_nr': '90000002'}
|
||||||
Reference in New Issue
Block a user