I have been reluctant to ask this question - I have been trying to solve it and have looked everywhere!
So, I run a company where we have several third parties emailing us with notifications of sales - all to different addresses. Each email to us is exactly one sale. The issue is that nowhere in the office is it possible to see the current total of sales (submissions) for that moment. I have been dying to learn Python since I was young so I figured that I would find a cool way to graphically display a sort of ticker that has a big number on a screen that we can hang on a wall in the office for everyone to see, via a Raspberry Pi and an LCD. But my gawd is this tough to do.
Outside of Python, it's all good to go, I have figured out the emailing to one inbox and I have managed to set a timer on our Gmail to mark the reads after 24hrs. The problem I am having is that I really want the program to update its counting of the unreads in real-time automatically without scrolling forever down the screen.
I have looked everywhere, loops don't seem to refresh the number on the window, nothing works apart from restarting the program again which is not automated and requires myself to start the program again. So, please, any help on this would be great. I plan to add graphics later, and maybe a little sound that goes ping or CHaaaChing when a sale comes in, but I thought I'd get this hard stuff out of the way first.
Here is my code:
#! /usr/bin/env python3.4
import imaplib
import email
from tkinter import *
root = Tk()
def window(main):
main.title('submissions counter')
width = 500
height = 500
x = (main.winfo_screenwidth() //2 ) - (width // 2)
y = (main.winfo_screenheight() //2 ) - (height // 2)
main.geometry('{}x{}+{}+{}'.format(width, height, x, y))
mail=imaplib.IMAP4_SSL('imap.gmail.com',993)
mail.login('email@gmail.com','Password')
mail.select("Submissions")
typ, messageIDs = mail.search(None, "UNSEEN")
messageIDsString = str( messageIDs[0], encoding='utf8' )
listOfSplitStrings = messageIDsString.split(" ")
if len(listOfSplitStrings) == 0:
print('no submissions')
elif len(listOfSplitStrings) == 1:
print(len(listOfSplitStrings),'submission[s]')
else:
print(len(listOfSplitStrings),'submission[s]')
def main_content():
hello = Label(root, text=(len(listOfSplitStrings),'submission[s]'))
hello.pack()
window(root)
main_content()
root.mainloop()
Now I am trying with this code and getting nothing from it at all, no error messages, no results on the text box or on the command line...
#! /usr/bin/env python3.4
import imaplib
import email
import tkinter as tk
WIDTH = 500
HEIGHT = 500
def update():
mail=imaplib.IMAP4_SSL('imap.gmail.com',993)
mail.login('email"gmail.com','password')
mail.select("Submissions")
typ, messageIDs = mail.search(None, "UNSEEN")
messageIDsString = str( messageIDs[0], encoding='utf8' )
listOfSplitStrings = messageIDsString.split(" ")
number = len(listOfSplitStrings)
if number == 0:
info['text'] = 'no submissions'
else:
info['text'] = '{} submissions[s]'.format(number)
root.after(5000, update)
root = tk.Tk()
root.title('submissions counter')
x = (root.winfo_screenwidth()//2) - (WIDTH//2)
y = (root.winfo_screenheight()//2) - (HEIGHT//2)
root.geometry('{}x{}+{}+{}'.format(WIDTH, HEIGHT, x, y))
info = tk.Label(root, text='no submissions')
info.pack
update()
root.mainloop()