Files
2025-10-30 12:42:52 +03:00

93 lines
4.2 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
# 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)
# проверяем наличие нужных листов
if "Получено от потребителей" not in dfs or "Возвращено потребителям" not in dfs:
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
# сама обработка
print("Реализация Яндекс")
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} отсутствуют необходимые листы")
print("Реализация WB")
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")