consolidator
/
NeuroDumper.py
55 строк · 2.3 Кб
1import glob
2import ntpath
3import os
4import pandas as pd
5from MyConfig import MyConfig
6from OraWorker import OraWorker
7
8cur_path = os.path.dirname(os.path.realpath(__file__))
9settings = MyConfig(f"{cur_path}\\config.json")
10user = settings.get("OracleConfig",defaultValue=None)["user"]
11passw = settings.get("OracleConfig",defaultValue=None)["pass"]
12dsn = settings.get("OracleConfig",defaultValue=None)["dsn"]
13cl = settings.get("OracleConfig",defaultValue=None)["client"]
14ora = OraWorker(user,passw,dsn,cl)
15
16def vm_handler(row:pd.Series)->pd.Series:
17try:
18row["Вид материала в SAP ERP"] = str(row["Вид материала в SAP ERP"])[0:4]
19check = ora.product_check("-",str(row["ID в SAP ERP VMZ"]))
20row["Укрупнено в продукт УП"] = check[0]
21print(f"check: {check[0]}")
22except Exception as exp:
23row["Полное наименование материала"]=f"{exp}"
24row["Укрупнено в продукт УП"] = "-"
25finally:
26return row
27
28if __name__=="__main__":
29try:
30
31pattern="D:\\work\\Укрупнение\\current\\data\\2024*\\*.xlsx"
32dump_dir="D:\\work\\Укрупнение\\current\\debug_data\\"
33exclude_pattern="нение_"
34neuro_columns=["ID в SAP ERP VMZ", "Вид материала в SAP ERP","Полное наименование материала"]
35files=[f for f in glob.glob(pattern) if exclude_pattern not in f] if exclude_pattern is not None else [f for f in glob.glob(pattern)]
36data={}
37list_data=[]
38for f in files:
39short_name = ntpath.basename(f)
40print(f"{f} -> {short_name} ---------------")
41xl = pd.ExcelFile(f)
42for sheet_name in xl.sheet_names:
43df=xl.parse(sheet_name=sheet_name)
44key = f"{dump_dir}[{short_name.replace('.xlsx','')}][{sheet_name}].xlsx"
45if not df.empty:
46if key not in data.keys():
47df=df[neuro_columns].apply(vm_handler,axis=1)
48list_data.append(df)
49result = pd.concat(list_data)
50result = result.drop_duplicates()
51result.to_excel(f"{dump_dir}neuro_dump.xlsx",index=False)
52print(f"{result.shape} -> done")
53ora.close()
54except Exception as exp:
55print(f"error: {exp}")