Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import email, getpass, imaplib, os, time
- # Declare functions here
- def move_forward():
- print "MOVE FORWARD"
- def move_backward():
- print "MOVE BACKWARD"
- def move_left():
- print "MOVE LEFT"
- def move_right():
- print "MOVE RIGHT"
- # END of functions declarations
- user = "USERNAME" #Change this
- pwd = "PASSWORD" #Change this
- m = imaplib.IMAP4_SSL("imap.gmail.com")
- m.login(user,pwd)
- #m.select("Inbox")
- #unread_messages = m.status('INBOX', "(UNSEEN)")
- #unreadcount = unread_messages[0].split()[2].strip(').,]')
- var = 1
- while var == 1:
- os.system('clear')
- m.select("Inbox")
- status, unreadcount = m.status('INBOX', "(UNSEEN)")
- unreadcount = int(unreadcount[0].split()[2].strip(').,]'))
- print "Unread Messages: " + str(unreadcount)
- if unreadcount > 0:
- items = m.search(None, "UNSEEN")
- #print items
- items = str(items[1]).strip('[\']').split(' ')
- #items = items[1].split(' ')
- #print items
- for index, emailid in enumerate(items):
- #print "emailid: " + emailid
- resp, data = m.fetch(emailid, "(RFC822)")
- #print str(data) + "\n"
- email_body = data[0][1]
- mail = email.message_from_string(email_body)
- if mail["Subject"] == 'robot instructions':
- print "From: " + mail["From"] + "\n"
- print "Subject: " + mail["Subject"] + "\n\n"
- for part in mail.walk():
- if part.get_content_type() == 'text/plain':
- body = part.get_payload()
- # For each line in message execute instructions
- counter = 1
- for line in body.split('\r\n'):
- counter = counter + 1
- #print "Instruction " + str(counter) + ": " + line
- if line == "forward":
- move_forward()
- elif line == "backward":
- move_backward()
- elif line == "left":
- move_left()
- elif line == "right":
- move_right()
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement