Created
June 6, 2019 20:23
-
-
Save sergiolucero/16ef496f9ec645a5436d7693f3289be7 to your computer and use it in GitHub Desktop.
parsing outlook folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, time | |
| from pprint import pprint | |
| from collections import defaultdict | |
| from win32com.client import Dispatch | |
| t0 = time.time() | |
| outlook=Dispatch("Outlook.Application").GetNamespace("MAPI") | |
| #inbox = outlook.GetDefaultFolder("6") | |
| confi = outlook.Folders(2).Folders(2) # found by trial and error | |
| counts = defaultdict(int) | |
| for aca in confi.Items: | |
| ax = aca.Attachments | |
| if ax.Count>0: | |
| print(ax.Count,aca.Subject) | |
| for att in ax: | |
| if '.pdf' in att.DisplayName: | |
| sender = aca.Sender() | |
| counter = counts[sender]+1 | |
| csender = sender.replace(' ','') | |
| csdir = os.path.join(os.getcwd(),'PDF',csender) | |
| if not os.path.exists(csdir): | |
| os.mkdir(csdir) | |
| filename = str(counter)+'_'+att.DisplayName | |
| ofn = os.path.join(os.getcwd(),'PDF',csender,filename) # overwrite? | |
| #print(sender) | |
| att.SaveAsFile(ofn) | |
| counts[sender]+=1 | |
| pprint(counts) | |
| print(sum(counts.values())) | |
| print(time.time()-t0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment