97 lines
4.8 KiB
Python
97 lines
4.8 KiB
Python
import pandas as pd
|
||
import server.backend.handlers.yandex_handler as yandex_handler
|
||
import server.backend.handlers.wb_handler as wb_handler
|
||
# def read_excel(base_dir):
|
||
# try:
|
||
# dfs = pd.read_excel(base_dir, sheet_name=None)
|
||
# return dfs
|
||
# except Exception as e:
|
||
# raise f"⚠️ Ошибка при чтении {file.name}: {e}"
|
||
|
||
class BaseHandler:
|
||
def __init__(self, file_path):
|
||
self.file_path = file_path
|
||
self.dfs = self.read()
|
||
|
||
def read(self):
|
||
try:
|
||
return pd.read_excel(self.file_path, sheet_name=None)
|
||
except Exception as e:
|
||
raise Exception(f"⚠️ Ошибка при чтении {self.file_path}: {e}")
|
||
|
||
def process(self):
|
||
raise NotImplementedError
|
||
|
||
class YandexHandler(BaseHandler):
|
||
def process(self):
|
||
# читаем Excel внутри объекта
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0, 1, 3])
|
||
# проверяем наличие нужных листов
|
||
if "Получено от потребителей" not in dfs or "Возвращено потребителям" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
# вызываем функцию evaluating
|
||
validated_data = yandex_handler.evaluating(dfs)
|
||
print("Реализация Яндекс завершена, валидированных строк:", len(validated_data[0]), "Реализация", len(validated_data[1]), "Возвраты")
|
||
|
||
class WBHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Sheet1" not in dfs :
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
validated_data = wb_handler.evaluating(dfs)
|
||
print("Реализация WB завершена, валидированных строк:", len(validated_data[0]), "Реализация", len(validated_data[1]), "Возвраты")
|
||
|
||
class OZONHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Отчет о реализации" not in dfs :
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
print("Реализация OZON")
|
||
|
||
class OZONPurchasesHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Отчет о выкупленных товарах" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
print("Выкупы озон")
|
||
|
||
class WBPurchasesHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Sheet1" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
print("Выкупы wb")
|
||
class OZONComHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Лист_1" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
df = dfs["Лист_1"]
|
||
cont = df.iloc[1, 0]
|
||
if cont != "«Интернет решения» ООО":
|
||
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
|
||
print("Товары, переданные на комиссию озон")
|
||
|
||
class WBComHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Лист_1" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
df = dfs["Лист_1"]
|
||
cont = df.iloc[1, 0]
|
||
if cont != '"Вайлдберриз" ООО':
|
||
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
|
||
print("Товары, переданные на комиссию wb")
|
||
|
||
class YandexComHandler(BaseHandler):
|
||
def process(self):
|
||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||
if "Лист_1" not in dfs:
|
||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||
df = dfs["Лист_1"]
|
||
cont = df.iloc[1, 0]
|
||
if cont != "Яндекс Маркет ООО":
|
||
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
|
||
print("Товары, переданные на комиссию yandex")
|
||
|