61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
import os
|
|
import chardet # pip install chardet
|
|
import traceback
|
|
from mail_order_bot.email_handler import EmailProcessor
|
|
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 = EmailProcessor("./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(
|
|
message=None,
|
|
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())
|
|
|
|
|