我对Python非常陌生,但对编程却并不陌生。我被要求访问Outlook日历中当前存在的所有约会。
我找到了一些代码,指出它将列出特定日期的所有约会。我希望以此为基础编写代码。
当我尝试运行代码时,除了以下消息外,什么都没有产生:
“ COMObject不明” 今天是2019-04-03 09:50:04.380469
我的感觉是Outlook帐户信息不足。那么代码如何知道在哪里看?
import win32com.client, datetime
def getCalendarEntries(days=1):
"""
Returns calender entries for days default is 1
"""
Outlook = win32com.client.Dispatch("Outlook.Application")
ns = Outlook.GetNamespace("MAPI")
calendar = ns.GetDefaultFolder(9)
appointments=calendar.Items
print (appointments)
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"
today = datetime.datetime.today()
print ('today is '+str(today))
begin = today.date().strftime("%m/%d/%Y")
tomorrow= datetime.timedelta(days=days)+today
end = tomorrow.date().strftime("%m/%d/%Y")
appointments = appointments.Restrict("[Start] >= '" +begin+ "' AND [END] <= '" +end+ "'")
events={'Start':[],'Subject':[],'Duration':[]}
for a in appointments:
adate=datetime.datetime.fromtimestamp(int(a.Start))
#print a.Start, a.Subject,a.Duration
events['Start'].append(adate)
events['Subject'].append(a.Subject)
events['Duration'].append(a.Duration)
return events
getCalendarEntries()
我希望从日历中获得约会清单。