Last active
August 29, 2015 14:24
-
-
Save arshpreetsingh/17be10e1ae5b59a771b6 to your computer and use it in GitHub Desktop.
This file contains 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
from imaplib import IMAP4_SSL | |
from datetime import date, timedelta, datetime | |
from time import mktime | |
from email.utils import parsedate | |
import email | |
import pygal | |
address = 'myid@gmail.com' | |
password = 'my gmail password' | |
inbox = 'INBOX' | |
outbox = '[Gmail]/Sent Mail' | |
d = 1 | |
def inbox_daily(address,password,inbox,d): | |
"""we are getting data from Inbox on the basis of TimeStamp""" | |
mail = IMAP4_SSL('imap.gmail.com') | |
mail.login(address, password) | |
mail.select(inbox) | |
"""Every Email_time stamp return a tuple""" | |
interval = (date.today()-timedelta(d)).strftime("%d-%b-%Y") | |
result, data = mail.uid('search', None,'(SENTSINCE {date})'.format(date=interval)) | |
xday = [] | |
Start_Day = (00,00,00) | |
Start_Day_List = [] | |
Mid_Morning = (06,00,00) | |
Mid_Morning_List = [] | |
Mid_Day = (12,00,00) | |
Mid_Day_List = [] | |
End_Day = (18,00,00) | |
End_Day_List = [] | |
Dead_End = (24,00,00) | |
Dead_End_List = [] | |
for num in data[0].split(): | |
result, data = mail.uid('fetch',num,'(RFC822)') | |
msg = email.message_from_string(data[0][1]) | |
main_tuple = email.utils.parsedate_tz(msg['Date']) | |
Date_Tuple = main_tuple[0],main_tuple[1],main_tuple[2] | |
Time_Tuple = main_tuple[3],main_tuple[4],main_tuple[5] | |
Today = datetime.today().timetuple() | |
Today_tuple = Today[0],Today[1],Today[2] | |
""" We are just comparing Static_tuples we defined with the one returning from Gmail_Data """ | |
if Date_Tuple==Today_tuple: | |
xday.append(Date_Tuple) | |
if Time_Tuple>Start_Day: | |
if Time_Tuple<Mid_Morning: | |
Start_Day_List.append(Time_Tuple) | |
if Time_Tuple>Mid_Morning: | |
if Time_Tuple<Mid_Day: | |
Mid_Morning_List.append(Time_Tuple) | |
if Time_Tuple>Mid_Day: | |
if Time_Tuple<End_Day: | |
Mid_Day_List.append(Time_Tuple) | |
if Time_Tuple>End_Day: | |
if Time_Tuple<Dead_End: | |
End_Day_List.append(Time_Tuple) | |
Start_day = len(Start_Day_List) | |
Mid_morning = len(Mid_Morning_List) | |
Mid_day = len(Mid_Day_List) | |
End_day = len(End_Day_List) | |
return Start_day,Mid_morning,Mid_day,End_day | |
aa,bb,cc,dd = inbox_daily(address,password,inbox,d) | |
stackedline_chart = pygal.StackedLine(fill=True) | |
stackedline_chart.title = 'Daily Email Analysis' | |
stackedline_chart.x_labels = ('Midnight','6 AM','Noon','6 PM') | |
stackedline_chart.add('Received',[aa,bb,cc,dd]) | |
stackedline_chart.render_to_file('honey5.svg') | |
stackedline_chart.render_to_file('honey1.svg') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment