Monitor experiment results on your Windows PC and Send progress report by Email using Python

Here is a python code which monitors the number of files in folders and sends a report every 15 minutes using Outlook account and Python (3.4). The code assumes that the interest is to get the number of files (the results are in files and thus interested in the number of files). However, the code could be easily adapted to user specific needs!! Python win32com package is needed.

import time
import os

import win32com.client as win32

TO = 'umar.waqas@somecool.mail'

main_path = 'c:\\folder\\path'
folders_to_watch = ['A', 'B', 'C']

# number of seconds between 2 messages
message_frequency = 60 * 15

report_count = 1

while True:

    message = "Folder status: <br/> "

    for f in folders_to_watch:
        number_of_files = len([name for name in os.listdir(main_path + f)])
        message = message + f + '[' + str(number_of_files) + ']' + '<br/>'

    
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = TO
    mail.Subject = 'Experiments status report - ' + str(report_count)
    mail.HtmlBody = message
    mail.send

    print('successfully sent ' + str(report_count) + ' emails')

    report_count = report_count + 1

    time.sleep(message_frequency)


print('End of folder watch')

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: