def process(self, text): words = text.lower().split(' ') if 'open' in words: speak_engine.say("I'm on it. Stand By.") websites = config["config"]["websites"] website_to_open = text[text.index('open') + 5:] if website_to_open in websites: url = websites[website_to_open] webbrowser.open_new_tab(url) if 'search' in words: speak_engine.say("I'm looking for it. Please stand by!") term_to_search = text[text.index('search') + 7:] summary = wikipedia.summary(term_to_search) summary = " ".join(re.findall('\w+.', summary)) summary = summary[:99] speak_engine.say(summary) return True if 'where' in words and ('are' in words or 'am' in words) and ('we' in words or 'i' in words) or 'location' in words: speak_engine.say("I am tracking the location. Stand by.") speak_engine.say(network.currentLocation()) return True if 'play' in words: if 'a' in words and 'song' in words: thread.start_new_thread(play_music, ()) return True if 'current' in words and 'time' in words: time = common.getCurrentTime() speak_engine.say(time) return True '''Handling Mathematical/Computational queries''' if 'add' in words or 'subtract' in words or 'multiply' in words or 'divide' in words: try: nums = re.findall('\d+', text) if len(nums) < 2: mod_text = words_to_nums(text) nums += re.findall('\d+', mod_text) print nums nums = map(int, nums) if 'add' in words: speak_engine.say("It is " + str(sum(nums))) if 'subtract' in words: speak_engine.say("It is " + str(nums[1] - nums[0])) if 'multiply' in words: speak_engine.say("It is " + str(nums[0] * nums[1])) if 'divide' in words: speak_engine.say("It is " + str(nums[0] / nums[1])) except: speak_engine.say( "Perhaps my Mathematical part of brain is malfunctioning.") return True return False
def process(self, text): words = text.lower().split(' ') if 'open' in words: speak_engine.say("I'm on it. Stand By.") websites = config["config"]["websites"] website_to_open = text[text.index('open') + 5:] if website_to_open in websites: url = websites[website_to_open] webbrowser.open_new_tab(url) if 'search' in words: speak_engine.say("I'm looking for it. Please stand by!") term_to_search = text[text.index('search') + 7:] summary = wikipedia.summary(term_to_search) summary = " ".join(re.findall('\w+.', summary)) summary = summary[:99] speak_engine.say(summary) return True if 'where' in words and ('are' in words or 'am' in words) and ('we' in words or 'i' in words) or 'location' in words: speak_engine.say("I am tracking the location. Stand by.") speak_engine.say(network.currentLocation()) return True if 'play' in words: if 'a' in words and 'song' in words: thread.start_new_thread(play_music, ()) return True if 'current' in words and 'time' in words: time = common.getCurrentTime() speak_engine.say(time) return True '''Handling Mathematical/Computational queries''' if 'add' in words or 'subtract' in words or 'multiply' in words or 'divide' in words: try: nums = re.findall('\d+', text) if len(nums) < 2: mod_text = words_to_nums(text) nums += re.findall('\d+', mod_text) print nums nums = map(int, nums) if 'add' in words: speak_engine.say("It is " + str(sum(nums))) if 'subtract' in words: speak_engine.say("It is " + str(nums[1] - nums[0])) if 'multiply' in words: speak_engine.say("It is " + str(nums[0] * nums[1])) if 'divide' in words: speak_engine.say("It is " + str(nums[0] / nums[1])) except: speak_engine.say( "Perhaps my Mathematical part of brain is malfunctioning.") return True if 'say' in words: speak_engine.say(text[text.index('say') + 4:]) return True if 'current' in words and 'temperature' in words: w = weather.Weather() speak_engine.say("The current temperature is " + w.getTemp()) return True if 'current' in words and 'weather' in words and 'condition' in words: w = weather.Weather() speak_engine.say("The current condition is " + w.getCondition()) return True if 'current' in words and 'weather' in words: w = weather.Weather() speak_engine.say("The temperature outside is " + w.getTemp() + 'and it is ' + w.getCondition()) return True if 'weather' in words and 'later' in words: w = weather.Weather() speak_engine.say(self.lenghtStr('It will be ' + w.getWeatherLater())) return True if 'weather' in words and 'tomorrow' in words: w = weather.Weather() speak_engine.say(self.lenghtStr('Tomorrow, it will be ' + w.getWeatherTomorrow())) return True if 'weather' in words and ('help' in words or 'command' in words): speak_engine.say('This is the commands for the weather.') print '-Current weather \n-Current temperature \n-Current weather condition \n-Weather later \n-Weather tomorrow' print '-Weather in X days ("X must be a number")' print '-Weather forecast (for the next six days)' print '\n\n' return True if 'weather' in words and ('day' in words or 'days' in words): w = weather.Weather() i = text.split(' ') x = int(i[-2]) speak_engine.say(self.lenghtStr(w.getWeatherNext(x))) return True if 'weather' in words and 'forecast' in words: w = weather.Weather() speak_engine.say('Here the forecast for the next six days.') print w.getWeatherNext(1) print w.getWeatherNext(2) print w.getWeatherNext(3) print w.getWeatherNext(4) print w.getWeatherNext(5) print w.getWeatherNext(6) print '\n\n' return True if 'update' in words and 'yourself' in words: speak_engine.say("Updating") subprocess.Popen("./gitUpdate.sh", shell=True) return True return False