For me it is not the mobile. It is the email, which is the most distraction application in office.
The variable reward system has become a habit. I tried closing it but then I keep missing meetings etc.
So had to keep it open just so the reminders for meetings show up.
Only reason I need the outlook is to have a day view why not print it. Bad option, see the already printed stack on my desk. Why not get all the events out for a day and use a text file on the desktop.
Therefore, that is what I did.
Here’s the python function to get the appointments of the day from outlook calendar.
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") appointments = ns.GetDefaultFolder(9).Items appointments.Sort("[Start]") appointments.IncludeRecurrences = "True" today = datetime.datetime.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
The functions spits out a dict and can be easily converted used in any way one wants.
Sweet! Let's see if am able to kill outlook now.
for me, %m/%d in strftime had to be reversed to %d/%m, and
adate=datetime.datetime.fromtimestamp(int(a.Start))
threw a type error
otherwise works like a charm. thank you!
LikeLike
Thanks for pointing this out. For me on my two systems it works as is. This means the system date format settings do play a role.
Thanks again for pointing this out.
LikeLike
Hi, I didn’t change the date format, and I get a type error with the adate in the For loop. This is the message i get :
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘pywintypes.datetime’
Since I am new to python, I feel I am a bit lost on how to solve it. Do you have any idea?
I managed to run the whole code with no errors, by commenting the adate lines.
thanks in advance
LikeLike
Sorry for the late reply. From your comment I am assuming you are working in python3. I will check and update the code for python3
LikeLike
Thanks Sukhbinder…
Any updare on the code for Python 3.7
LikeLike
Will check and see I can get access to python and outlook on a same machine. I will fix this soon?
LikeLike
Hi Win, please find the python 3 version at the following post https://sukhbinder.wordpress.com/?p=4109
LikeLike
I also have the TypeError, could you help me with this?
line 20, in getCalendarEntries
adate=datetime.datetime.fromtimestamp(int(a.Start))
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘pywintypes.datetime’
LikeLike
I have to check this… Thanks for pointing this out…
LikeLike
Pingback: Get Outlook Entries With Python 3 | SukhbinderSingh.com
Is there any way to make this work using Microsoft Outlook on a Mac?
LikeLike
In theory this should be possible but I haven’t checked it.
LikeLike