feature/evaluating #2
10
makefile
10
makefile
@@ -1,4 +1,12 @@
|
|||||||
VENV=source ./.venv/bin/activate;
|
VENV=source ./.venv/bin/activate;
|
||||||
.PHONY: run
|
.PHONY: run run_full run_stocks run_orgs run_contractors
|
||||||
run:
|
run:
|
||||||
$(VENV) python run.py
|
$(VENV) python run.py
|
||||||
|
run_full:
|
||||||
|
$(VENV) python run.py --mode full
|
||||||
|
run_stocks:
|
||||||
|
$(VENV) python run.py --mode stocks
|
||||||
|
run_orgs:
|
||||||
|
$(VENV) python run.py --mode orgs
|
||||||
|
run_contractors:
|
||||||
|
$(VENV) python run.py --mode contractors
|
||||||
27
run.py
27
run.py
@@ -1,3 +1,30 @@
|
|||||||
import server.backend.services.excel as excel
|
import server.backend.services.excel as excel
|
||||||
from server.backend.services.validating_files import validating
|
from server.backend.services.validating_files import validating
|
||||||
|
from server.backend.api import companies,contractors,storages
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser(description="Экспорт в Excel")
|
||||||
|
parser.add_argument(
|
||||||
|
"--mode",
|
||||||
|
choices=["stocks", "orgs", "contractors", "full", "standart"],
|
||||||
|
default="standart",
|
||||||
|
help="Режим экспорта (по умолчанию: standart)"
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
match args.mode:
|
||||||
|
case "full":
|
||||||
|
print("Режим:", args.mode)
|
||||||
|
companies.companies()
|
||||||
|
contractors.contractor()
|
||||||
|
storages.storages()
|
||||||
|
case "orgs":
|
||||||
|
print("Режим:", args.mode)
|
||||||
|
companies.companies()
|
||||||
|
case "contractors":
|
||||||
|
print("Режим:", args.mode)
|
||||||
|
contractors.contractor()
|
||||||
|
case "stocks":
|
||||||
|
print("Режим:", args.mode)
|
||||||
|
storages.storages()
|
||||||
|
case "standart":
|
||||||
|
print("Режим:", args.mode)
|
||||||
print(validating())
|
print(validating())
|
||||||
@@ -40,6 +40,7 @@ def parse_contragents(xml: str):
|
|||||||
return df
|
return df
|
||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
raise
|
raise
|
||||||
xml_data = fetch_contragents()
|
def companies():
|
||||||
root = parse_contragents(xml_data)
|
xml_data = fetch_contragents()
|
||||||
print(root)
|
root = parse_contragents(xml_data)
|
||||||
|
root.to_excel("./excel_files/companies.xlsx")
|
||||||
@@ -44,6 +44,7 @@ def parse_contragents(xml: str):
|
|||||||
return df
|
return df
|
||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
raise
|
raise
|
||||||
xml_data = fetch_contragents()
|
def contractor():
|
||||||
root = parse_contragents(xml_data)
|
xml_data = fetch_contragents()
|
||||||
print(root)
|
root = parse_contragents(xml_data)
|
||||||
|
root.to_excel("./excel_files/contractors.xlsx")
|
||||||
@@ -42,6 +42,6 @@ def parse_contragents(xml: str):
|
|||||||
return df
|
return df
|
||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
raise
|
raise
|
||||||
xml_data = fetch_contragents()
|
def nomenclature():
|
||||||
root = parse_contragents(xml_data)
|
xml_data = fetch_contragents()
|
||||||
print(root)
|
root = parse_contragents(xml_data)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ def parse_contragents(xml: str):
|
|||||||
return df
|
return df
|
||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
raise
|
raise
|
||||||
xml_data = fetch_contragents()
|
def storages():
|
||||||
root = parse_contragents(xml_data)
|
xml_data = fetch_contragents()
|
||||||
print(root)
|
root = parse_contragents(xml_data)
|
||||||
|
root.to_excel("./excel_files/storages.xlsx")
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
from server.backend.schemas.pydantic import ExcelInfo,settings
|
from server.backend.schemas.pydantic import ExcelInfo,settings
|
||||||
|
from server.backend.api.nomenclature import nomenclature
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum_2:str):
|
def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum_2:str):
|
||||||
@@ -21,6 +22,7 @@ def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum
|
|||||||
errors.append((i, e.errors())) #выводит ошибку и пишет номер строки
|
errors.append((i, e.errors())) #выводит ошибку и пишет номер строки
|
||||||
if errors:
|
if errors:
|
||||||
raise Exception(f"There are some errors with validation in Отчет о реализации, check it ", errors)
|
raise Exception(f"There are some errors with validation in Отчет о реализации, check it ", errors)
|
||||||
|
|
||||||
return validated_rows
|
return validated_rows
|
||||||
def evaluating(dfs):
|
def evaluating(dfs):
|
||||||
validated_rows_1 = process_sheet(dfs["Отчет о реализации"], real_arti='2',real_quantity='8', real_sum_1='5',real_sum_2='6') # номера столбцов от озона
|
validated_rows_1 = process_sheet(dfs["Отчет о реализации"], real_arti='2',real_quantity='8', real_sum_1='5',real_sum_2='6') # номера столбцов от озона
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ class BaseHandler:
|
|||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
self.dfs = self.read()
|
self.dfs = self.read()
|
||||||
|
|
||||||
def read(self):
|
def read(self, skiprows=None, skipfooter=0):
|
||||||
try:
|
try:
|
||||||
return pd.read_excel(self.file_path, sheet_name=None)
|
return pd.read_excel(self.file_path, sheet_name=None, skiprows=skiprows,skipfooter=skipfooter)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"⚠️ Ошибка при чтении {self.file_path}: {e}")
|
raise Exception(f"⚠️ Ошибка при чтении {self.file_path}: {e}")
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class YandexHandler(BaseHandler):
|
|||||||
def process(self):
|
def process(self):
|
||||||
# читаем Excel внутри объекта
|
# читаем Excel внутри объекта
|
||||||
#доставать дату
|
#доставать дату
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0, 1, 3]) #skip header
|
dfs = self.read(skiprows=[0,1,3])
|
||||||
# проверяем наличие нужных листов
|
# проверяем наличие нужных листов
|
||||||
if "Получено от потребителей" not in dfs or "Возвращено потребителям" not in dfs:
|
if "Получено от потребителей" not in dfs or "Возвращено потребителям" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
@@ -33,7 +33,7 @@ class YandexHandler(BaseHandler):
|
|||||||
|
|
||||||
class WBHandler(BaseHandler):
|
class WBHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
dfs = self.read()
|
||||||
#доставать дату по месяцу и просто день ставить последний
|
#доставать дату по месяцу и просто день ставить последний
|
||||||
if "Sheet1" not in dfs :
|
if "Sheet1" not in dfs :
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
@@ -43,7 +43,7 @@ class WBHandler(BaseHandler):
|
|||||||
class OZONHandler(BaseHandler):
|
class OZONHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
#Доставать № документа и дату
|
#Доставать № документа и дату
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=14, skipfooter=17) #skip the header and the footer
|
dfs = self.read(skiprows=14, skipfooter=17)
|
||||||
if "Отчет о реализации" not in dfs:
|
if "Отчет о реализации" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
validated_data = ozon_handler.evaluating(dfs)
|
validated_data = ozon_handler.evaluating(dfs)
|
||||||
@@ -52,7 +52,7 @@ class OZONHandler(BaseHandler):
|
|||||||
class OZONPurchasesHandler(BaseHandler):
|
class OZONPurchasesHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
#доставать дату и номер документа
|
#доставать дату и номер документа
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=12, skipfooter=1)
|
dfs = self.read(skiprows=12, skipfooter=1)
|
||||||
if "Отчет о выкупленных товарах" not in dfs:
|
if "Отчет о выкупленных товарах" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
validated_data = ozon_purchases_handler.evaluating(dfs)
|
validated_data = ozon_purchases_handler.evaluating(dfs)
|
||||||
@@ -60,7 +60,7 @@ class OZONPurchasesHandler(BaseHandler):
|
|||||||
|
|
||||||
class WBPurchasesHandler(BaseHandler):
|
class WBPurchasesHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=9, skipfooter=7)
|
dfs = self.read(skiprows=9, skipfooter=7)
|
||||||
if "Sheet1" not in dfs:
|
if "Sheet1" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
validated_data = wb_purchases_handler.evaluating(dfs)
|
validated_data = wb_purchases_handler.evaluating(dfs)
|
||||||
@@ -68,7 +68,7 @@ class WBPurchasesHandler(BaseHandler):
|
|||||||
|
|
||||||
class OZONComHandler(BaseHandler):
|
class OZONComHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
dfs = self.read(skipfooter=1)
|
||||||
if "Лист_1" not in dfs:
|
if "Лист_1" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
df = dfs["Лист_1"]
|
df = dfs["Лист_1"]
|
||||||
@@ -81,7 +81,7 @@ class OZONComHandler(BaseHandler):
|
|||||||
|
|
||||||
class WBComHandler(BaseHandler):
|
class WBComHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
dfs = self.read(skipfooter=1)
|
||||||
if "Лист_1" not in dfs:
|
if "Лист_1" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
df = dfs["Лист_1"]
|
df = dfs["Лист_1"]
|
||||||
@@ -94,7 +94,7 @@ class WBComHandler(BaseHandler):
|
|||||||
|
|
||||||
class YandexComHandler(BaseHandler):
|
class YandexComHandler(BaseHandler):
|
||||||
def process(self):
|
def process(self):
|
||||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
dfs = self.read(skipfooter=1)
|
||||||
if "Лист_1" not in dfs:
|
if "Лист_1" not in dfs:
|
||||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||||
df = dfs["Лист_1"]
|
df = dfs["Лист_1"]
|
||||||
|
|||||||
Reference in New Issue
Block a user