【发布时间】:2019-12-06 16:12:51
【问题描述】:
我从 Outlook 获取日历结果,仅获取每个日历项的开始时间和主题。
import win32com, win32com.client
import datetime, time, pytz
def getCalendarEntries():
Outlook = win32com.client.Dispatch("Outlook.Application")
appointments = Outlook.GetNamespace("MAPI").GetDefaultFolder(9).Items
appointments.Sort("[Start]");
appointments.IncludeRecurrences = "True"
today = datetime.datetime.today().date().strftime("%Y-%d-%m")
tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y-%d-%m")
appointments = appointments.Restrict("[Start] >= '" +today+"' AND [Start] < '"+tomorrow+"'");
events={'Start':[],'Subject':[]}
for a in appointments:
events['Start' ].append(a.Start );
events['Subject'].append(a.Subject)
return events
calendar = getCalendarEntries();
n=len(calendar['Start']);
i=0;
while( n ):
print(
calendar['Start'][i] ,
calendar['Subject'][i]
);
n-=1;
i+=1;
这是结果,而且是正确的:
$ py test_outlook.py
2019-12-06 10:00:00+00:00 test apointment
我现在需要处理上面的数据以仅获取时间:10:00,这样我就可以进行计算并找出距离活动开始还有多少时间......就像距离 10 分钟一样, 1 小时后,等等。
我真的不知道该怎么做……有人知道吗?
【问题讨论】:
标签: python