Рефаткоринг, добавляю пайплайн
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# Конфигурационный файл для контрагента todx.ru
|
||||
|
||||
pipeline:
|
||||
# Обработчик вложений
|
||||
- handler: "BasicExcelParser"
|
||||
config:
|
||||
sheet_name: 0
|
||||
key_field: "Код детали"
|
||||
mapping:
|
||||
article: "Код детали"
|
||||
manufacturer: "Производитель"
|
||||
name: "Наименование"
|
||||
price: "Цена\nдетали"
|
||||
quantity: "Кол-\nво"
|
||||
total: "Сумма"
|
||||
|
||||
- handler: InstantOrderTest
|
||||
config:
|
||||
api_key: "8056899069:AAFEfw9QRMvmEwQyH0CI4e_v_sZuOSdNWcE"
|
||||
chat_id: 211945135
|
||||
|
||||
- handler: "TestNotifier"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import chardet # pip install chardet
|
||||
import traceback
|
||||
from mail_order_bot.task_handler import TaskProcessor
|
||||
import datetime
|
||||
# установим рабочую директорию
|
||||
import os
|
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
from io import BytesIO
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.WARNING, format='%(module)s - %(message)s') # %(asctime)s -
|
||||
BASE_PATH = './files'
|
||||
|
||||
|
||||
from mail_order_bot.email_client import EmailMessage, EmailAttachment
|
||||
|
||||
processor = TaskProcessor("./configs")
|
||||
|
||||
for provider_name in os.listdir(BASE_PATH):
|
||||
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()
|
||||
|
||||
# Создаем объект EmailAttachment
|
||||
att = EmailAttachment(file_name, raw_data)
|
||||
email = EmailMessage(
|
||||
from_addr=provider_name,
|
||||
from_email='test@gmail.com',
|
||||
subj='order request',
|
||||
dt=datetime.datetime.now(),
|
||||
body= 'body text',
|
||||
attachments=[att],
|
||||
first_sender='test@gmail.com'
|
||||
)
|
||||
|
||||
|
||||
|
||||
#bio = BytesIO(raw_data)
|
||||
print("========================================================")
|
||||
print(f'Обработка: {provider_name} - {file_name}')
|
||||
try:
|
||||
|
||||
positions_a = processor.process(provider_name, att)
|
||||
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"Ошибка обработки: {e}", traceback.format_exc())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user