Files
Excel-project/server/backend/excel.py
2025-11-08 22:09:10 +03:00

108 lines
6.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pandas as pd
import server.backend.handlers.yandex_handler as yandex_handler
import server.backend.handlers.wb_handler as wb_handler
import server.backend.handlers.ozon_handler as ozon_handler
import server.backend.handlers.ozon_purchases_handler as ozon_purchases_handler
import server.backend.handlers.wb_purchases_handler as wb_purchases_handler
import server.backend.handlers.ozon_wb_yandex_com_handler as ozon_wb_yandex_com_handler
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]) #skip header
# проверяем наличие нужных листов
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, skiprows=14, skipfooter=17) #skip the header and the footer
if "Отчет о реализации" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
validated_data = ozon_handler.evaluating(dfs)
print("Реализация OZON завершена, валидированных строк:", len(validated_data[0]), "Реализация", len(validated_data[1]), "Возвраты")
class OZONPurchasesHandler(BaseHandler):
def process(self):
#доставать дату и номер документа
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=12, skipfooter=1)
if "Отчет о выкупленных товарах" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
validated_data = ozon_purchases_handler.evaluating(dfs)
print("Выкупы OZON завершены, валидированных строк:", len(validated_data), "Реализация")
class WBPurchasesHandler(BaseHandler):
def process(self):
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=9, skipfooter=7)
if "Sheet1" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
validated_data = wb_purchases_handler.evaluating(dfs)
print("Выкупы WB завершены, валидированных строк:", len(validated_data), "Реализация")
class OZONComHandler(BaseHandler):
def process(self):
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
if "Лист_1" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
df = dfs["Лист_1"]
cont = df.iloc[1, 0]
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0,2],skipfooter=1)
if cont != "«Интернет решения» ООО":
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
validated_data = ozon_wb_yandex_com_handler.evaluating(dfs)
print("Передача на коммисию OZON завершена, валидированных строк:", len(validated_data), "Реализация")
class WBComHandler(BaseHandler):
def process(self):
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
if "Лист_1" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
df = dfs["Лист_1"]
cont = df.iloc[1, 0]
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0,2], skipfooter=1)
if cont != '"Вайлдберриз" ООО':
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
validated_data = ozon_wb_yandex_com_handler.evaluating(dfs)
print("Передача на коммисию WB завершена, валидированных строк:", len(validated_data), "Реализация")
class YandexComHandler(BaseHandler):
def process(self):
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
if "Лист_1" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
df = dfs["Лист_1"]
cont = df.iloc[1, 0]
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0,2], skipfooter=1)
if cont != "Яндекс Маркет ООО":
raise Exception(f"В файле {self.file_path.name} неверный контрагент")
validated_data = ozon_wb_yandex_com_handler.evaluating(dfs)
print("Передача на коммисию YANDEX завершена, валидированных строк:", len(validated_data), "Реализация")