def checkGmail(self): """ Description: Checks the unread count in gMail """ global unread_Count global unread_Count_new unread_Count_new = utilities.getUnreadCount() if (unread_Count < unread_Count_new): logger.info("a new email has arrived") logger.info("Speaking email notification") emailQuips = [ "Yet another email", "Pardon the interruption sir. Another email has arrived for you to ignore." ] tempint = randint(1, len(emailQuips)) utilities.speakString(emailQuips[tempint - 1]) if (unread_Count_new != 0): logger.info("unread Count: " + str(unread_Count_new)) unread_Count = unread_Count_new
def checkGmail(self): """ Description: Checks the unread count in gMail """ logger.info("checking Gmail") global unread_Count unread_Count_new = utilities.getUnreadCount() if (unread_Count < unread_Count_new): logger.info("a new email has arrived") utilities.speakString("Pardon the interruption sir.") utilities.speakString("Another email has arrived for you to ignore.") if (unread_Count_new != 0): logger.info("unread Count: "+str(unread_Count_new)) unread_Count = unread_Count_new
def playTune(self): """ Description: pick a random song from current weather category and play it """ currentConditions = utilities.getValue("conditionsText") logger.info("Current Conditions obtained: "+currentConditions) """ Options are: ============ Mostly Cloudy Light Rain .... """ # read config file config.read(os.path.join(CURRENT_PATH,'../config/alfr3ddaemon.conf')) logger.info("read config file") # select a random song to play given certain weather conditions try: tempint = random.randint(1,5) cond = config.get(currentConditions, str(tempint)) logger.info("found a weather appropriate song") utilities.speakString("This should cheer you up.") print "song to play: /home/alfr3d/audio/"+cond logger.info("playing sond: "+cond) os.system("sudo mplayer -ao alsa:device=default -really-quiet -noconsolecontrols home/alfr3d/audio/"+cond) #example: os.system("sudo mplayer -ao alsa:device=default -really-quiet -noconsolecontrols home/alfr3d/audio/Gus black - paranoid.mp3") except: logger.warn("could not find a suitable song for the given weather: "+currentConditions) songs=[] for root,dirs,files in os.walk("/home/alfr3d/audio/",topdown=False): for filename in files: if filename.endswith(".mp3"): result = os.path.join(root,filename) songs.append(result) randsong = random.choice(songs) randsong = randsong.replace(" ","\\ ") randsong = randsong.replace("(","\\(") randsong = randsong.replace(")","\\)") randsong = randsong.replace("'","\\'") randsong = randsong.replace("&","\\&") print ("playing song: "+randsong) logger.info("playing song: "+randsong) utilities.speakString("I couldn\'t find an appropriate song for the weather.") utilities.speakString("but i went into your music library and found this") os.system("sudo mplayer -ao alsa:device=default -really-quiet -noconsolecontrols "+randsong)
def init_daemon(): """ Description: initialize alfr3d services """ utilities.speakString("Initializing systems check") faults = 0 # initial geo check try: utilities.speakString("Running geo scan") logger.info("Running a geoscan") ret = utilities.getLocation("freegeoip") if not ret[0]: raise Exception("Geo scan failed") utilities.speakString("Geo scan complete") except Exception, e: utilities.speakString("Failed to complete geo scan") logger.error("Failed to complete geoscan scan") logger.error("Traceback: " + str(e)) faults += 1 # bump up fault counter
Checks the unread count in gMail """ logger.info("checking Gmail") global unread_Count global unread_Count_new try: unread_Count_new = utilities.getUnreadCount() logger.info("Gmail check successful") except Exception, e: logger.error("Gmail check failed") logger.error("Traceback "+str(e)) if (unread_Count < unread_Count_new): logger.info("a new email has arrived") utilities.speakString("Pardon the interruption sir.") utilities.speakString("Another email has arrived for you to ignore.") if (unread_Count_new != 0): logger.info("unread Count: "+str(unread_Count_new)) unread_Count = unread_Count_new def welcomeHome(self,time_away=None): """ Description: Speak a 'welcome home' greeting """ logger.info("Greeting the creator") utilities.speakWelcome(time_away)
def speakString(command): utilities.speakString(command) log.write(strftime("%H:%M:%S: ")+"Received request: speakString") return template('<b>Spoke {{string}}</b>!',string=command)
# software/component specified under (i). # import os import sys from random import randint from time import time, strftime, localtime #import my own utilities sys.path.append(os.path.join(os.path.join(os.getcwd(),os.path.dirname(__file__)),"../")) import utilities utilities.speakGreeting() if (strftime("%p",localtime()) == "AM"): utilities.speakString("your time to rest has come to an end") utilities.speakTime() utilities.speakDate() loc = utilities.getLocation() utilities.getWeather(loc[1],loc[2]) unread_count = utilities.getUnreadCount() if unread_count > 1: utilities.speakString("While you were sleeping "+str(unread_count)+" emails flooded your inbox") sys.exit(1) else: utilities.speakTime() random = [
try: utilities.speakString("Running geo scan") logger.info("Running a geoscan") ret = utilities.getLocation("freegeoip") if not ret[0]: raise Exception("Geo scan failed") utilities.speakString("Geo scan complete") except Exception, e: utilities.speakString("Failed to complete geo scan") logger.error("Failed to complete geoscan scan") logger.error("Traceback: " + str(e)) faults += 1 # bump up fault counter #initial lighting check try: utilities.speakString("Running lighting check") logger.info("Running a lighting check") utilities.lightingInit() utilities.speakString("lighting check complete") except Exception, e: utilities.speakString("Failed to complete lighting check") logger.error("Failed to complete lighting check") logger.error("Traceback: " + str(e)) faults += 1 # bump up fault counter #initial coffee check try: utilities.speakString("Looking for a source of coffee") logger.info("Running a coffee check") utilities.coffeeCheck() utilities.speakString("Brew check complete")