# React to ear movement program # Put in task scheduler, checks every 5 minutes # Edited 12/2: corrected error: close bunnyFile after done # changed pickling to use ascii files, rather than binary # removed error handling upon opening pickle file # added print statements to help debug. import xml.dom.minidom import pickle from Nabaztag import * # Read the bunny info, ignore desired voice and zip code (used for weather program) bunnyFile = open('wxBunnyFile.txt', "r") data = bunnyFile.readlines() bunnyFile.close() # Strip of the new line characters sn=data[0][:-1] token=data[1][:-1] myNab = Nabaztag(sn, token) # Message to say if left ear has moved. msgLeft="Hay! Who woke me up?... Has someone been moving my ears? You better watch out. I am a killer rabbit. I have a vicious streak a mile wide, and nasty, big, pointy teeth! . . Just kidding!" mp3Right="4063557" # Get old ear positions from pickle file earFile = open('oldEarPositionFile.p', "r") ## try: oldPositions = pickle.load(earFile) ##except: ## oldPositions = ['/u0','/u0'] earFile.close # Get ear positions position=myNab.getEars() dom=parseString(position) leftPosition = dom.firstChild.getElementsByTagName('leftposition')[0].firstChild.data rightPosition = dom.firstChild.getElementsByTagName('rightposition')[0].firstChild.data dom.unlink() newPositions = [leftPosition,rightPosition] # Pickle to save old ear position earFile = open('oldEarPositionFile.p', "w") pickle.dump(newPositions, earFile) earFile.close print 'old positions: ',oldPositions print 'new positions: ',newPositions # If ears moved, send message if newPositions[0] <> oldPositions[0]: # Send text to speech using Ryan voice myNab.say(msgLeft, "Aaron22s") if newPositions[1] <> oldPositions[1]: # Send "Hey, technology is beautiful" mp3 myNab.sendMessage(mp3Right)