-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoutlook.py
46 lines (39 loc) · 2.08 KB
/
outlook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from win32com.client import Dispatch
from tabulate import tabulate
from datetime import datetime, timedelta
import pdb
import pandas as pd
class Outlook_task:
def getCalendarEntry(self):
OUTLOOK_FORMAT = '%d/%m/%Y %H:%M'
outlook = Dispatch("Outlook.Application")
ns = outlook.GetNamespace("MAPI")
appointments = ns.GetDefaultFolder(9).Items
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"
today = datetime.now()
begin = today.date().strftime("%d/%m/%Y")
tomorrow=timedelta(days=10)+today
end = tomorrow.date().strftime("%d/%m/%Y")
appointments = appointments.Restrict("[Start] >= '" +begin+ "' AND [END] <= '" +end+ "'")
events={'Start':[],'Subject':[],'Duration':[]}
keys = ('Title', 'Organizer', 'Start', 'Duration(Minutes)')
calcTable = dict.fromkeys(keys)
for appointmentItem in appointments:
if calcTable['Title']==None:
calcTable['Title'] = appointmentItem.Subject
calcTable['Organizer'] = appointmentItem.Organizer
calcTable['Start'] = appointmentItem.Start.Format(OUTLOOK_FORMAT)
calcTable['Duration(Minutes)'] = appointmentItem.Duration
elif type(calcTable['Title']) == list:
calcTable['Title'].append(appointmentItem.Subject)
calcTable['Organizer'].append(appointmentItem.Organizer)
calcTable['Start'].append(appointmentItem.Start.Format(OUTLOOK_FORMAT))
calcTable['Duration(Minutes)'].append(appointmentItem.Duration)
else:
calcTable['Title'] = [calcTable['Title'],appointmentItem.Subject]
calcTable['Organizer'] = [calcTable['Organizer'],appointmentItem.Organizer]
calcTable['Start'] = [calcTable['Start'], appointmentItem.Start.Format(OUTLOOK_FORMAT)]
calcTable['Duration(Minutes)'] = [calcTable['Duration(Minutes)'], appointmentItem.Duration]
dfs = pd.DataFrame.from_dict([calcTable])
return dfs