Python 循环不完全遵守既定规则
Python loop not fully respecting a set rule
我希望尽快根据共享 Outlook 邮箱中的发件人标记电子邮件。
#imports:
import time
from time import strftime
import pandas as pd, win32com.client as client
from win32.com.client import Dispatch
#importing the excel file that contains email addresses and corresponding flags:
df_excel = pd.read_excel(r'\user\...\addresses.xlsx')
#adding both columns as lists:
df_excel_mail = df_excel['mail'].tolist();df_excel_flag = df_excel['flag'].tolist()
outlook = client.Dispatch('Outlook.Application').GetNamespace('MAPI')
main_account = outlook.Folders.Item(1)
folder_inbox = main_account.Folders['Inbox'].Folders['Test']
folder_inbox_WIP = main_account.Folders['Inbox'].Folders['Test'].Folders['WIP']
while True:
time.sleep(0)
messages = folder_inbox.Items.Count
if messages > 0:
for i in reversed(range(0,messages)):
message = folder_inbox.Item[i]
for y, z, in zip(df_excel_mail,df_excel_flag)
if message.Categories == '' and y == message.SenderEmailAddress
message.Categories = z
message.Save
message.Move(folder_inbox_WIP)
messages_v2 = folder_inbox_WIP.Items.Count
if folder_inbox_WIP .Items.Count > 0:
for ii in reversed (range(0,messages_v2)):
message_v2 = folder_inbox_WIP[ii]
message_v2.Move(folder_inbox)
if strftime('%H, %M, %N') >= strftime('18:00:00')
break
我的addresses.xlsxsheet看起来是这样的:
邮件
旗帜
aaa.bbb@mail.com
红色
ccc.ddd@outlook.com
绿色
...
...
eee.fff@client.com
...
...
当电子邮件地址在 df_excel_mail 列表中可用但在 df_excel_flag 列表中缺少相应的标志颜色时。有些电子邮件无论如何都会发送到 WIP 文件夹并标记为#QNAN。
当以下代码本应防止这种情况发生时,这怎么可能?
if message.Categories == '' and y == message.SenderEmailAddress
问题与数据框中的 'NaN' 值有关,我使用 .notna() 来修复它
我希望尽快根据共享 Outlook 邮箱中的发件人标记电子邮件。
#imports:
import time
from time import strftime
import pandas as pd, win32com.client as client
from win32.com.client import Dispatch
#importing the excel file that contains email addresses and corresponding flags:
df_excel = pd.read_excel(r'\user\...\addresses.xlsx')
#adding both columns as lists:
df_excel_mail = df_excel['mail'].tolist();df_excel_flag = df_excel['flag'].tolist()
outlook = client.Dispatch('Outlook.Application').GetNamespace('MAPI')
main_account = outlook.Folders.Item(1)
folder_inbox = main_account.Folders['Inbox'].Folders['Test']
folder_inbox_WIP = main_account.Folders['Inbox'].Folders['Test'].Folders['WIP']
while True:
time.sleep(0)
messages = folder_inbox.Items.Count
if messages > 0:
for i in reversed(range(0,messages)):
message = folder_inbox.Item[i]
for y, z, in zip(df_excel_mail,df_excel_flag)
if message.Categories == '' and y == message.SenderEmailAddress
message.Categories = z
message.Save
message.Move(folder_inbox_WIP)
messages_v2 = folder_inbox_WIP.Items.Count
if folder_inbox_WIP .Items.Count > 0:
for ii in reversed (range(0,messages_v2)):
message_v2 = folder_inbox_WIP[ii]
message_v2.Move(folder_inbox)
if strftime('%H, %M, %N') >= strftime('18:00:00')
break
我的addresses.xlsxsheet看起来是这样的:
邮件 | 旗帜 |
---|---|
aaa.bbb@mail.com | 红色 |
ccc.ddd@outlook.com | 绿色 |
... | ... |
eee.fff@client.com | |
... | ... |
当电子邮件地址在 df_excel_mail 列表中可用但在 df_excel_flag 列表中缺少相应的标志颜色时。有些电子邮件无论如何都会发送到 WIP 文件夹并标记为#QNAN。
当以下代码本应防止这种情况发生时,这怎么可能?
if message.Categories == '' and y == message.SenderEmailAddress
问题与数据框中的 'NaN' 值有关,我使用 .notna() 来修复它