Привет, я хочу перенести тело сообщения из Outlook в фрейм данных. Сообщение имеет две возможности форматирования: 1.
`Supplier TN No. Supplier Name File Name File Date
AAA595014655 XXX Tungsten_SPF_2020WK21.csv_27-05-2020_15-41-19-683_A 27/05/2020
Processed Accepted Failed
91 91 0
Ignored Invoices 0
Failed Invoices
Invoice No. Invoice Date Customer TN No. Customer Name Invoice Type Gross Amount PO Number Failure Code Failure Reason
Accepted Invoices
Invoice No. Invoice Date Customer TN No. Customer Name Invoice Type Gross Amount Currency Transaction Number
9036728752 19/05/2020 AAA276999224 CustomerN Invoice 1,708.74 USD AAA000192388488
9036736098 20/05/2020 AAA276999224 CustomerN Invoice 6.20 USD AAA000192388494
9036736108 20/05/2020 AAA276999224 CustomerN Invoice 14,382.88 USD AAA000192388514
9036756938 22/05/2020 AAA276999224 CustomerN Invoice 134,029.12 USD AAA000192388563
9036756824 22/05/2020 AAA276999224 CustomerN Invoice 681.72 USD AAA000192388551
9036756950 22/05/2020 AAA276999224 CustomerN Invoice 21.74 USD AAA000192388525
9036756951 22/05/2020 AAA276999224 CustomerN Invoice 677.97 USD AAA000192388527
9036722017 18/05/2020 AAA276999224 CustomerN Invoice 57,945.08 USD AAA000192388498
9036736100 20/05/2020 AAA276999224 CustomerN Invoice 2,282.63 USD AAA000192388524
9036728770 19/05/2020 AAA276999224 CustomerN Invoice 8,802.27 USD AAA000192388565
9036721316 18/05/2020 AAA276999224 CustomerN Invoice 1,728.64 USD AAA000192388484
6000547208 26/05/2020 AAA559077144 CustomerN Invoice 340,212.29 USD AAA000192388542
9036728760 19/05/2020 AAA276999224 CustomerN Invoice 1,423.95 USD AAA000192388537
9036728769 19/05/2020 AAA276999224 CustomerN Invoice 27,498.25 USD AAA000192388518
9036728767 19/05/2020 AAA276999224 CustomerN Invoice 14,690.63 USD AAA000192388515
Failed Invoices: any failed invoices listed have not been successfully processed and therefore have not been delivered by Tungsten Network to your Client Buyer. Please correct the error indicated by the failure reason code and then resubmit your invoices to Tungsten Network. If you continue to have problems, please contact Tungsten Network Support at http://www.Tungsten-network.com/support
This is a notification from the TN system and is for information only
Wed May 27 2020 15:42:46 GMT+0100 (BST)
Есть больше счетов и второй формат
2.
Supplier TN No. Supplier Name File Name File Date
AAA684691561 XXX AAA684691561_43452417.xml_27-05-2020_08-28-46-254_A 27/05/2020
Processed Accepted Failed
1 1 0
Ignored Invoices 0
Failed Invoices
Invoice No. Invoice Date Customer TN No. Customer Name Invoice Type Gross Amount PO Number Failure Code Failure Reason
Accepted Invoices
Invoice No. Invoice Date Customer TN No. Customer Name Invoice Type Gross Amount Currency Transaction Number
6000547043 25/05/2020 AAA559077144 CustomerN Invoice 225,720.14 USD AAA000192366243
Failed Invoices: any failed invoices listed have not been successfully processed and therefore have not been delivered by Tungsten Network to your Client Buyer. Please correct the error indicated by the failure reason code and then resubmit your invoices to Tungsten Network. If you continue to have problems, please contact Tungsten Network Support at http://www.Tungsten-network.com/support
This is a notification from the TN system and is for information only
Wed May 27 2020 08:29:02 GMT+0100 (BST)
Второй формат простой, и этот код работает
# Get today's mails from tungsten folder
outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")
date = datetime.date.today()
L = []
your_folder = mapi.Folders['123123@xxx.com'].Folders['Inbox'].Folders['Tungsten']
for message in your_folder.Items:
if date == message.senton.date():
ms = message.body
for x in range(1):
L.append(ms)
df = pd.DataFrame(L, columns=['string_values'])
df1 = df['string_values'].str.split('\r', 50, expand=True)
#Select needed column
df2 = df1.iloc[:, [38, 39, 45]]
# rename columns
df2 = df2.rename(columns={df2.columns[0]: 'Invoice_No.', df2.columns[1]: 'Tungsten_Date',
df2.columns[2]: 'Tungsten_No'})
, например, если я получаю два письма с двумя, при его форматировании будет создан этот фрейм данных
Invoice_No Tungsten_Date Tungsten_No
6000547043 2020-05-28 AAA000192366243
6000547042 2020-05-28 AAA000192366354
Но я не знаю, как изменить сценарий, когда у меня несколько счет в одном письме. Формат этих двух типов писем всегда одинаковый,
Спасибо за любую помощь