Jul-22-2018, 08:06 AM
Hello everyone,
Now I am nearly done with this mini 'project' but being so inexperienced with python I am trying make the code run until the user terminates the script. I have tried crontab but it doesnt appear to be working for some reason which I will investigate later.
Instead I have tried to initiate a loop to ensure that the script checks the email inbox repeatedly but I keep making mistakes and looping the incorrect part of the code.
Would I put the loop in the section where the code gets the messages from the server? I have tried a simple x=1 while x=1 and while true but ive ended up in infinite loops breaking the machine im working on. I just want to loop the bit to get the messages and then if the subject "bananas are the greatest nut" is found then it executes the webbrowser function. Can anyone advise?
Now I am nearly done with this mini 'project' but being so inexperienced with python I am trying make the code run until the user terminates the script. I have tried crontab but it doesnt appear to be working for some reason which I will investigate later.
Instead I have tried to initiate a loop to ensure that the script checks the email inbox repeatedly but I keep making mistakes and looping the incorrect part of the code.
import poplib import webbrowser from email import parser pop_conn = poplib.POP3_SSL('pop.gmail.com') pop_conn.user('USERNAME') pop_conn.pass_('PASSWORD!') #Get messages from server: messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)] # Concat message pieces: messages = ["\n".join(mssg[1]) for mssg in messages] #Parse message intom an email object: messages = [parser.Parser().parsestr(mssg) for mssg in messages] for message in messages: if "bananas are the greatest nut" in message['subject'].lower(): webbrowser.open('/home/pi/Desktop/PIC.jpg') pop_conn.quit()
Would I put the loop in the section where the code gets the messages from the server? I have tried a simple x=1 while x=1 and while true but ive ended up in infinite loops breaking the machine im working on. I just want to loop the bit to get the messages and then if the subject "bananas are the greatest nut" is found then it executes the webbrowser function. Can anyone advise?