#Ted Ullrich with the help of Tom Morgan #tullrich@gmail.com #tedullrich.com #Georgia Intitute of Technology #College of Architecture — Industrial Design Program #Final Project for Masters of Industrial Design #Spring 2009 # #Upon launch, this file asks for the user's Gmail account name and password. #Then it queries for a keyword, asking, "In one word, what do the contents of the physical device represent to you?" #The program then embarks on a day's worth loop of checking the user's Gmail box for the percentage of emails containting the keyword. #The program sends the specific alpha letters to the USB serial port to allow the pre-programmed Arduino to act appropriately (see stepper.pde sketch) #!/usr/bin/env ruby require 'serialport.so' #used for serial communicatio to the arduino require "rubygems" require 'net/imap' #used for connecting to the email account require 'highline/import' #used for simplifying text input/output as well as obfusticating the password #serial port set up port_str = "/dev/tty.usbserial-A7005YB4" #HIGHLY LIKELY TO CHANGE!! this need to be changed on a per user basis to point to the arduino or it will not work baud_rate = 9600 data_bits = 8 stop_bits = 1 parity = SerialPort::NONE seconds_in_day = 86400 frequency_to_check = 10 #CHANGE THIS TO CHANGE FREQUENCY OF CHECKING number_times_to_loop = seconds_in_day / frequency_to_check #used for creating a loop, will be implemented in the future t = Time.now servicename = 'Gmail' service = 'imap.gmail.com' #end search_variable = ask('In one word, what do the contents of the physical device represent to you?: ') #end #get the username and password username = ask("Enter your Gmail username: " ) password = ask("Enter your Gmail password: " ) { |q| q.echo = "*" } mastercounter = 0 totalold = 1.000 #sets the message counters to zero keyold = 0.000 #sets the message counters to zero while (mastercounter < number_times_to_loop) #log in with username and password with ssl encryption imap = Net::IMAP.new(service,'993',true) imap.login(username, password) say("Logged in: Checking Mail...\n") totalnew = 1.000 #sets the message counters to zero keynew = 0.000 #sets the message counters to zero imap.select('INBOX') #imap.search(["FROM", field, "NOT", "SEEN"]).each do |message_id| #imap.search(["LARGER", 100000]).each do |message_id| #imap.search(["LARGER", 100000]).each do |message_id| #imap.search(["NOT", "SEEN"]).each do |message_id| #imap.search(["TEXT", 'Thanks']).each do |message_id| imap.search(["ALL"]).each do |message_id| totalnew += 1.000 end #end for search for total messages imap.search(["TEXT", search_variable]).each do |message_id| envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"] say("#{envelope.from[0].name}: \t #{envelope.subject} \n") keynew += 1.000 end #end for search for new messages quotientnew = (keynew / totalnew) quotientold = (keyold / totalold) percentage = quotientnew - quotientold say(keynew.to_s + " keyword messages found \n") say(totalnew.to_s + " total messages found \n") # say(quotientnew.to_s + " quotient new \n\n") # say(keyold.to_s + " keyold \n") # say(totalold.to_s + " totalold \n") # say(quotientold.to_s + " quotient old \n\n") percentageprint = percentage*100 say("reflecting a " + percentageprint.to_s + "% change in keyword messages \n") quotientnewprint = quotientnew*100 say("DISPLAYING " + quotientnewprint.to_s + "% OF KEYWORD EMAILS IN INBOX\n\n") sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity) #open serial port if(percentage < 0) sp.write('u') #tell the arduino to flip directions before sending the next value percentage = (percentage * -1) end #end if if(percentage == 0) say("No new messages were found\n\n\n") end #end if if(percentage > 0 && percentage < 0.05) say("between 0% and 5% change\n\n\n") sp.write('a') end #end if if(percentage >= 0.05 && percentage < 0.1) say("between 5% and 10% change\n\n\n") sp.write('b') end #end if if(percentage >= 0.10 && percentage < 0.15) say("between 10% and 15% change\n\n\n") sp.write('c') end #end if if(percentage >= 0.15 && percentage < 0.2) say("between 15% and 20% change\n\n\n") sp.write('d') end #end if if(percentage >= 0.2 && percentage < 0.25) say("between 20% and 25% change\n\n\n") sp.write('e') end #end if if(percentage >= 0.25 && percentage < 0.3) say("between 25% and 30% change\n\n\n") sp.write('f') end #end if if(percentage >=0.3 && percentage < 0.35) say("between 30% and 35% change\n\n\n") sp.write('g') end #end if if(percentage >= 0.35 && percentage < 0.4) say("between 35% and 40% change\n\n\n") sp.write('h') end #end if if(percentage >= 0.4 && percentage < 0.45) say("between 40% and 45% change\n\n\n") sp.write('i') end #end if if(percentage >= 0.45 && percentage < 0.5) say("between 45% and 50% change\n\n\n") sp.write('j') end #end if if(percentage >= 0.5 && percentage < 0.55) say("between 50% and 55% change\n\n\n") sp.write('k') end #end if if(percentage >= 0.55 && percentage < 0.6) say("between 55% and 60% change\n\n\n") sp.write('l') end #end if if(percentage >= 0.6 && percentage < 0.65) say("between 60% and 65% change\n\n\n") sp.write('m') end #end if if(percentage >= 0.65 && percentage < 0.7) say("between 65% and 70% change\n\n\n") sp.write('n') end #end if if(percentage >= 0.7 && percentage < 0.75) say("between 70% and 75% change\n\n\n") sp.write('o') end #end if if(percentage >= 0.75 && percentage < 0.8) say("between 75% and 80% change\n\n\n") sp.write('p') end #end if if(percentage >= 0.8 && percentage < 0.85) say("between 80% and 85% change\n\n\n") sp.write('q') end #end if if(percentage >= 0.85 && percentage < 0.9) say("between 85% and 90% change\n\n\n") sp.write('r') end #end if if(percentage >= 0.9 && percentage < 0.95) say("between 90% and 95% change\n\n\n") sp.write('s') end #end if if(percentage >= 0.95 && percentage <= 1) say("between 95% and 100% change") sp.write('t') end #end if sp.close #close serial port #update the values keyold = keynew totalold = totalnew imap.logout() #log out of the email account mastercounter += 1 sleep(frequency_to_check) #pause and wait for the next cycle end#end for while