my net house

WAHEGURU….!

A reusable function

def fetch_uids(address,password,folder,d):
mail = IMAP4_SSL(‘imap.gmail.com’)
mail.login(address, password)
mail.select(folder)
interval = (date.today()-timedelta(days)).strftime(“%d-%b-%Y”)
result, data = mail.uid(‘search’, None,'(SENTSINCE {date})’.format(date=interval))
return data

 

 

Now I can define variables according to my project and using the function call I can make my function more reusable:

for daily analysis inbox I can call:

fetch_uids(address,password,folder=’INBOX’,days=0)

 

for daily analysis sentbox I can call:

fetch_uids(address,password,folder='[Gmail]/Sent’,days=0)

Same as I can change the value of ‘days’ which make more sense.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: