Try parse first excel file

This commit is contained in:
2025-11-08 21:46:34 +03:00
parent bd1faa5a79
commit f6d186ab56
13 changed files with 270 additions and 23 deletions

View File

@@ -0,0 +1,36 @@
import os
import chardet # pip install chardet
from ..src.mail_order_bot.excel_processor import ExcelProcessor
BASE_PATH = './files'
ep = ExcelProcessor("./suppliers.yml")
print("================================================")
for provider_name in os.listdir(BASE_PATH):
print(f'Провайдер: {provider_name}')
provider_folder = os.path.join(BASE_PATH, provider_name)
if os.path.isdir(provider_folder):
for file_name in os.listdir(provider_folder):
file_path = os.path.join(provider_folder, file_name)
if os.path.isfile(file_path):
with open(file_path, 'rb') as file: # бинарный режим
raw_data = file.read()
detected = chardet.detect(raw_data)
encoding = detected['encoding'] or 'utf-8'
try:
data = raw_data.decode(encoding)
except (UnicodeDecodeError, TypeError):
# Если декодировать не удалось, попробуем utf-8 игнорируя ошибки
data = raw_data.decode('utf-8', errors='ignore')
print(f'Файл: {file_name}')
#print(f'Содержимое: {data}')

View File

@@ -0,0 +1,77 @@
suppliers:
# order@stparts.ru
"order@stparts.ru":
sheet_name: "TDSheet" # Название листа Excel
header_row: 0 # Номер строки с заголовками (0 = первая)
# Маппинг: внутреннее_поле -> названиеолонки_в_Excel
mapping:
article: "Номер"
manufacturer: "Бренд"
name: "Описание"
price: "Цена"
quantity: "Количество"
#total: "Сумма"
#Вопросы: что за поле "Фактическая_отгрузка"?
# Дополнительные настройки (опционально)
options:
decimal_separator: ","
encoding: "utf-8"
# Рай Авто СПб
EMPTY-FROM:
sheet_name: 0
header_row: 2 # Заголовки во второй строке
mapping:
article: "Артикул"
manufacturer: "Производитель"
name: "Название"
price: "Цена"
quantity: "Количество"
#total: "Сумма с НДС"
options:
decimal_separator: ","
encoding: "utf-8"
#thousand_separator: ","
# Примечание: гемор - нет имейла
# АвтоТО
"order@avtoto.ru":
sheet_name: "Заказы" # Можно указать индекс листа
header_row: 4
mapping:
article: "Артикул"
manufacturer: "Изготовитель"
name: "Наименование товара"
price: "Цена"
quantity: "Кол-во"
total: "Сумма"
options:
#skip_footer_rows: 3
decimal_separator: ","
# автолига.рф
"автолига.рф":
sheet_name: 0 # Можно указать индекс листа
header_row: 8
mapping:
article: "Артикул"
manufacturer: "Производитель"
name: "Название детали"
price: "Цена, р."
quantity: "Количество"
total: "Сумма, р."
options:
#skip_footer_rows: 3
decimal_separator: ","