Advertisement
Guest User

Untitled

a guest
Jul 13th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.98 KB | None | 0 0
  1. from tkinter import *
  2. import time
  3. import imaplib
  4. import sys
  5. import email
  6. import email.header
  7. import datetime
  8.  
  9. INBOX = "INBOX"
  10.  
  11. def LoginValidate():
  12.     success = 1
  13.     try:
  14.         short.login(entryUsername.get(), entryPassword.get())
  15.     except short.error:
  16.         print("loginerror")
  17.         success = 0
  18.     if success == 1:
  19.         MainWindow()
  20.     else:
  21.         print("loginerror")
  22.  
  23. def LoginShort(event):
  24.     print("hello")
  25.     LoginValidate()
  26.  
  27.  
  28. def ButtonCommand():
  29.     EmailGet(short)
  30.  
  31.  
  32. def EmailGet(short):
  33.     check, blank = short.select(INBOX)
  34.     if check != "OK":
  35.         print("No inbox!")
  36.    
  37.     if  boxTime.get() == "One Day":
  38.         dayrange = 1
  39.         print("dayrange 1")
  40.     elif boxTime.get() == "One Week":
  41.         dayrange = 7
  42.         print("dayrange 7")
  43.     elif boxTime.get() == "30 Days":
  44.         dayrange = 30
  45.         print("dayrange 30")
  46.     elif boxTime.get() == "One Year":
  47.         dayrange = 365
  48.         print("dayrange 1")
  49.  
  50.              
  51.     check, emails = short.search(None, '(SUBJECT "Dollar Solar Website Contact Form Submission")')
  52.     if check != "OK":
  53.         print("No emails!")
  54.     email_list = emails[0].split()
  55.     for i in email_list:
  56.         check, email_info, = short.fetch(i, '(RFC822)')
  57.         if check != "OK":
  58.             print("Cannot extract email data")
  59.         else:
  60.             print(i)
  61.            
  62.             details = email.message_from_bytes(email_info[0][1])
  63.             details_date = email.utils.parsedate_tz(details['Date'])
  64.  
  65.             datelist = []
  66.             datelist.append(details_date[0:3])
  67.             print(datelist)
  68.  
  69.             date_year = (int(details_date[0]))
  70.             date_month = (int(details_date[1]))
  71.             date_day = (int(details_date[2]))
  72.            
  73.             datedays = datetime.date(date_year,date_month,date_day)
  74.             todaydate = datetime.date.today()
  75.  
  76.             if abs(todaydate-datedays).days >= dayrange:
  77.                 print("OUT OF DATE RANGE")
  78.             else:
  79.                 print("WITHIN DATE RANGE")
  80.                 for part in details.walk():
  81.                     if part.get_content_type() == 'text/plain':
  82.                         print(part.get_payload())
  83.                         emailDisplay.insert(END, part.get_payload())
  84.        
  85.        
  86.            
  87.        
  88.  
  89. def MainWindow():
  90.     mWindow = Toplevel(root)
  91.     mWindow.minsize(width=600, height=400)
  92.     mWindow.title("Dollar Solar Database Manager")
  93.    
  94.     labStatus = Label(mWindow, text="Logged in successfully, awaiting processing...", fg=("green"))
  95.     labStatus.grid(row=0, sticky=W)
  96.  
  97.     labGuidance = Label(mWindow, text="Please select a time range, and click the button")
  98.     labGuidance.grid(row=1, sticky=W)
  99.  
  100.     global boxTime
  101.     boxTime = Spinbox(mWindow,values=("One Day", "One Week", "30 Days", "One Year"), state="readonly")
  102.     boxTime.grid(row=2, column=0, sticky=W)
  103.    
  104.     buttonAdd = Button(mWindow, text = ("Add to DB"), command=ButtonCommand)
  105.     buttonAdd.place(x=135,y=40)
  106.  
  107.     global emailDisplay
  108.     emailDisplay = Text(mWindow, fg="gray")
  109.     emailDisplay.grid(row=3, column=0, sticky=W)
  110.    
  111.        
  112. short = imaplib.IMAP4_SSL("imap.gmail.com")
  113.  
  114. root = Tk()
  115. root.title("Dollar Solar Database Manager")
  116. root.maxsize(width=600, height=350)
  117. loginmessage = Label(root, text = "Please Log In", font=("Cambria",28))
  118. loginmessage.grid(row=0, sticky=N)
  119.  
  120. labUsername = Label(root, text = ("EMAIL:"))
  121. labUsername.grid(row=1, sticky =W)
  122.  
  123.  
  124. entryUsername = Entry(root, text = (""))
  125. entryUsername.grid(row=1, column =0, sticky=E)
  126. entryUsername.bind("<Return>",LoginShort)
  127.  
  128. labPassword = Label(root, text = ("PASSWORD:"))
  129. labPassword.grid(row=2, sticky=W)
  130.  
  131. entryPassword = Entry(root, text = (""),show="*")
  132. entryPassword.grid(row=2, column =0, sticky=E)
  133. entryPassword.bind("<Return>",LoginShort)
  134.  
  135. buttonConfirm = Button(root, text = ("LOGIN"), command=LoginValidate)
  136. buttonConfirm.grid(row =1,column =1, sticky=E)
  137.  
  138. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement