--- a/report.py +++ b/report.py @@ -1,6 +1,8 @@ import argparse import datetime import query +import gmail +import mailConfig parser = argparse.ArgumentParser(description="""Generate report for the date specified. Start and end date default to present day. @@ -10,18 +12,15 @@ parser.add_argument('-e','--end-date', type=str, default=datetime.datetime.strftime(datetime.date.today(), '%Y-%m-%d'), help="End date (YYYY-MM-DD)") parser.add_argument('-S','--start-time', type=str, default = '00:00:00', help="Start time (HH:MM:SS)") parser.add_argument('-E','--end-time', type=str, default='23:59:59', help="End time (HH:MM:SS)") +parser.add_argument('-p','--print', type=bool, default=True, help="Print report on command line") +parser.add_argument('-m','--mail', type=bool, default=False, help="Mail report to addressess in mailConfig.py") args = parser.parse_args() startDate = args.start_date + " " + args.start_time endDate = args.end_date + " " + args.end_time - postings = query.Query('lb_postings') -print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) -print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) -print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) - callDetails = query.Query('cdr') average_call_length = callDetails.average(startDate, endDate) audio_minutes = callDetails.sum(startDate, endDate) @@ -31,24 +30,35 @@ mobilink_load = callDetails.call_distribution(startDate, endDate, 'mobilink') mobilink_tata_load = callDetails.call_distribution(startDate, endDate, 'mobilinktata') +if args.mail is False: + print '{0}: {1}'.format("Number of postings published", postings.posts(startDate, endDate)) + print '{0}: {1}'.format("Number of recordings made", postings.recordings(startDate, endDate)) + print '{0}: {1}'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) + print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) + print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) + print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) + print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) + print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) + print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) + print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) + print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) + print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) + print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) + print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) + print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) + print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) + print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) + print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) + print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) + print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) + print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) + print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) -print '{0}: {1}'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) -print '{0}: {1}'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) -print '{0}: {1}'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) -print '{0}: {1}'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) -print '{0}: {1}'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) -print '{0}: {1:.4f}'.format("Average length of calls", average_call_length) -print '{0}: {1:.4f}'.format("Total number of audio minutes played", audio_minutes) -print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) -print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) -print '{0}: {1:.4f}'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) -print '{0}: {1:.4f}'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) -print '{0}: {1:.4f}'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) -print '{0}: {1:.4f}'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) -print '{0}: {1}'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) -print '{0}: {1}'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) -print '{0}: {1}'.format("Least active hour for mobilink",mobilink_load["minLoad"]) -print '{0}: {1}'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) -print '{0}: {1}'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) -print '{0}: {1}'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) +else: + report = '{0}: {1}\n'.format("Number of postings published", postings.posts(startDate, endDate)) + '{0}: {1}\n'.format("Number of recordings made", postings.recordings(startDate, endDate)) + '{0}: {1}\n'.format("Number of impact stories", postings.filter_by_title('impact', startDate, endDate)) + '{0}: {1}\n'.format("Number of missed calls", callDetails.missedCalls(startDate, endDate)) + '{0}: {1}\n'.format("Number of missed calls on 'mobilink'", callDetails.missedCalls(startDate, endDate, 'mobilink')) + '{0}: {1}\n'.format("Number of missed calls on 'mobilinktata'", callDetails.missedCalls(startDate, endDate, 'mobilinktata')) + '{0}: {1}\n'.format("Number of calls answered", callDetails.answeredCalls(startDate, endDate)) + '{0}: {1}\n'.format("Number of calls lasting less than 30 seconds", callDetails.filter_calls_by_duration(startDate, endDate, 30)) + '{0}: {1:.4f}\n'.format("Average length of calls", average_call_length) + '{0}: {1:.4f}\n'.format("Total number of audio minutes played", audio_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.20", channel1_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.21", channel2_minutes) + '{0}: {1:.4f}\n'.format("Audio minutes on channel 10.0.0.22", channel3_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.20", channel1_minutes/audio_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.21", channel2_minutes/audio_minutes) + '{0}: {1:.4f}\n'.format("Load on channel 10.0.0.22", channel3_minutes/audio_minutes) + '{0}: {1}\n'.format("Busiest hour for mobilink",mobilink_load["maxLoad"]) + '{0}: {1}\n'.format("Number of calls in busiest hour for mobilink",mobilink_load["maxCalls"]) + '{0}: {1}\n'.format("Least active hour for mobilink",mobilink_load["minLoad"]) + '{0}: {1}\n'.format("Busiest hour for mobilinktata",mobilink_tata_load["maxLoad"]) + '{0}: {1}\n'.format("Number of calls in busiest hour for mobilinktata",mobilink_tata_load["maxCalls"]) + '{0}: {1}\n'.format("Least active hour for mobilinktata",mobilink_tata_load["minLoad"]) + + + mail = gmail.GMail(mailConfig.username, mailConfig.password) + message = gmail.Message(mailConfig.subject, mailConfig.to, text=report) + mail.send(message)