diff --git a/Excel/kirurgji_1662981526.xlsx b/Excel/kirurgji_1662981526.xlsx new file mode 100644 index 0000000..3e5ea01 Binary files /dev/null and b/Excel/kirurgji_1662981526.xlsx differ diff --git a/llogarit_moshen.py b/llogarit_moshen.py index 2c1f3cc..50e34f5 100644 --- a/llogarit_moshen.py +++ b/llogarit_moshen.py @@ -1,3 +1,5 @@ +import os +from posixpath import dirname import pandas as pd from datetime import datetime import calendar @@ -12,15 +14,15 @@ class Klinika(Enum): URGJENCA = 'urgjenca' -klinika = Klinika.KIRURGJI.value +klinika = Klinika.OBS.value xlsx_path = './Excel/' -excel_path = join(xlsx_path, "raw_{klinika}_2016-2019.xlsx") +excel_path = join(xlsx_path, f"raw_{klinika}_2016-2019.xlsx") df = pd.read_excel(excel_path, sheet_name='Sheet1') df = df.reset_index() -df['MOSHA'] = [None] * 2384 -df['ERROR'] = [None] * 2384 +df['MOSHA'] = [None] * df.index.stop +df['ERROR'] = [None] * df.index.stop i = 0 datat_pattern = "%d/%m/%y" data_shtri_korigj = [] @@ -49,6 +51,9 @@ def konverto_data(datat: str, i: int): datat = int(datat) / 12 df.iat[i, df.columns.get_loc('MOSHA')] = float(datat) return "DEKLARUAR" + if datat.endswith('/'): + datat = datat[:-1] + print(datat) datat = datat.split('/') if len(datat) == 1: datat.insert(0, '1') @@ -92,7 +97,10 @@ def pastro_string(datat: str, i: int): for index, row in df.iterrows(): - data_shtri = row['DATA E SHTRIMIT'] + try: + data_shtri = row['DATA E SHTRIMIT'] + except KeyError as e: + data_shtri = row['DATA'] datelindja = row['DATELINDJA'] emer = row['EMER'] data_shtri = pastro_string(data_shtri, i) @@ -111,12 +119,19 @@ for index, row in df.iterrows(): datelindja_korigj.append(datelindja) i += 1 -df.insert(16, "DT_SHTRIMI_KORIGJ", data_shtri_korigj) -df.insert(17, "DATELINDJA_KORIGJ", datelindja_korigj) +df.insert(len(df.columns), "DT_SHTRIMI_KORIGJ", data_shtri_korigj) +df.insert(len(df.columns), "DATELINDJA_KORIGJ", datelindja_korigj) + df.drop(columns=df.columns[0], axis=1, inplace=True) current_GMT = time.gmtime() ts = calendar.timegm(current_GMT) -excel_path = join(xlsx_path, "{klinika}_{ts}.xlsx") +for dirpath, dirname, filename in os.walk(xlsx_path): + for name in filename: + if name.startswith(klinika): + file_per_tu_fshire = join(xlsx_path, name) + os.remove(file_per_tu_fshire) + +excel_path = join(xlsx_path, f"{klinika}_{ts}.xlsx") df.to_excel(excel_path, index=False)