def how_am_i(text): replies = [ 'You are goddamn handsome!', 'My knees go weak when I see you.', 'You are sexy!', 'You look like the kindest person that I have ever met!' ] tts(random.choice(replies))
def who_are_you(text): va_name = profile.data['va_name'] messages = [ 'I am ' + va_name + ', your lovely personal assistant.', va_name + ', didnt I tell you before?', 'You ask that so many times! I am ' + va_name ] tts(random.choice(messages))
def show_all_notes(text): conn = sqlite3.connect(profile.data['memory_db']) tts('Your notes are as follows:') cursor = conn.execute("SELECT notes FROM notes") for row in cursor: tts(row[0]) conn.close()
def show_all_uploads(text): conn = sqlite3.connect(profile.data['memory_db']) cursor = conn.execute("SELECT * FROM image_uploads") for row in cursor: print(row[0] + ': (' + row[1] + ') on ' + row[2]) tts('Requested data has been printed on your terminal') conn.close()
def play_shuffle(text): try: mp3gen() random.shuffle(music_listing) for i in range(0, len(music_listing)): music_player(music_listing[i]) except IndexError as e: tts('No music files found.') print("No music files found: {0}".format(e))
def play_random(text): try: mp3gen() music_playing = random.choice(music_listing) song_name = os.path.splitext(basename(music_playing[1]))[0] tts("Now playing: " + song_name) music_player(music_playing) except IndexError as e: tts('No music files found.') print("No music files found: {0}".format(e))
def note_something(speech_text): conn = sqlite3.connect(profile.data['memory_db']) words_of_message = speech_text.split() words_of_message.remove('note') cleaned_message = ' '.join(words_of_message) conn.execute( "INSERT INTO notes (notes, notes_date) VALUES (?, ?)", (cleaned_message, datetime.strftime(datetime.now(), '%d-%m-%Y'))) conn.commit() conn.close() tts('Your note has been saved.')
def find_iphone(text): try: api = PyiCloudService(ICLOUD_USERNAME, ICLOUD_PASSWORD) except PyiCloudFailedLoginException: tts("Invalid Username & Password") return # All Devices devices = api.devices # Just the iPhones iphones = [] for device in devices: current = device.status() if "iPhone" in current['deviceDisplayName']: iphones.append(device) # The one to ring phone_to_ring = None if len(iphones) == 0: tts("No iPhones found in your account") return elif len(iphones) == 1: phone_to_ring = iphones[0] phone_to_ring.play_sound() tts("Sending ring command to the phone now") elif len(iphones) > 1: for phone in iphones: phone_to_ring = phone phone_to_ring.play_sound() tts("Sending ring command to the phone now")
def weather(text): weather_com_result = pywapi.get_weather_from_weather_com( profile.data['city_code']) current_conditions = weather_com_result['current_conditions'] temperature = float(current_conditions['temperature']) degrees_type = 'celsius' if profile.data['degrees'] == 'fahrenheit': temperature = (temperature * 9 / 5) + 32 degrees_type = 'fahrenheit' weather_result = "Weather.com says: It is " + \ weather_com_result['current_conditions']['text'].lower() + \ " and " + str(temperature) + " degrees " + degrees_type + \ " now in " + profile.data['city_name'] print(weather_result) tts(weather_result)
def define_subject(speech_text): words_of_message = speech_text.split() words_of_message.remove('define') cleaned_message = ' '.join(words_of_message).rstrip() if len(cleaned_message) == 0: msg = 'define requires subject words' print msg tts(msg) return try: wiki_data = wikipedia.summary(cleaned_message, sentences=5) regEx = re.compile(r'([^\(]*)\([^\)]*\) *(.*)') m = regEx.match(wiki_data) while m: wiki_data = m.group(1) + m.group(2) m = regEx.match(wiki_data) wiki_data = wiki_data.replace("'", "") tts(wiki_data) except wikipedia.exceptions.DisambiguationError as e: tts('Can you please be more specific? You may choose something' + 'from the following.') print("Can you please be more specific? You may choose something" + "from the following; {0}".format(e))
def iphone_battery(text): try: api = PyiCloudService(ICLOUD_USERNAME, ICLOUD_PASSWORD) except PyiCloudFailedLoginException: tts("Invalid Username & Password") return # All Devices devices = api.devices # Just the iPhones iphones = [] for device in devices: current = device.status() if "iPhone" in current['deviceDisplayName']: iphones.append(device) for phone in iphones: status = phone.status() battery = str(int(float(status['batteryLevel']) * 100)) tts(battery + 'percent battery left in ' + status['name'])
def ip_address(text): tts("Here are my available I.P. addresses.") for ifaceName in interfaces(): addresses = [ i['addr'] for i in ifaddresses(ifaceName).setdefault( AF_INET, [{'addr': None}])] if None in addresses: addresses.remove(None) if addresses and ifaceName != "lo": updated_addresses = [re.sub(r"\.", r" dot ", address) for address in addresses] tts('%s: %s' % ("interface: " + ifaceName + ", I.P. Address ", ', '.join(updated_addresses))) tts("Those are all my I.P. addresses.")
def image_uploader(speech_text): if profile.data['imgur']['client_id'] == "xxxx" \ or profile.data['imgur']['client_secret'] == "xxxx": msg = 'upload requires a client id and secret' print msg tts(msg) return words_of_message = speech_text.split() words_of_message.remove('upload') cleaned_message = ' '.join(words_of_message) if len(cleaned_message) == 0: tts('upload requires a picture name') return image_listing = img_list_gen() client = ImgurClient(profile.data['imgur']['client_id'], profile.data['imgur']['client_secret']) for i in range(0, len(image_listing)): if cleaned_message in image_listing[i]: result = client.upload_from_path(image_listing[i], config=None, anon=True) conn = sqlite3.connect(profile.data['memory_db']) conn.execute("INSERT INTO image_uploads " "(filename, url, upload_date) VALUES (?, ?, ?)", (image_listing[i], result['link'], datetime.strftime(datetime.now(), '%d-%m-%Y'))) conn.commit() conn.close() print result['link'] tts('Your image has been uploaded')
def where_born(text): tts('I was created by a magician named Tanay, in India, ' 'the magical land of himalayas.')
def who_am_i(text): name = profile.data['name'] tts('You are ' + name + ', a brilliant person. I love you!')
def toss_coin(text): outcomes = ['heads', 'tails'] tts('I just flipped a coin. It shows ' + random.choice(outcomes))
def very_dark(text): subprocess.call(['blink1-tool', '--white']) tts('Better now?')
def undefined(text): tts('I dont know what that means!')
def love_you(text): replies = [ 'I love you too.', 'You are looking for love in the wrong place.' ] tts(random.choice(replies))
def feeling_lazy(text): subprocess.call(['blink1-tool', '--yellow']) tts('Rise and shine dear!')
def feeling_creative(text): subprocess.call(['blink1-tool', '--magenta']) tts('So good to hear that!')
def feeling_angry(text): subprocess.call(['blink1-tool', '--cyan']) tts('Calm down dear!')
def how_are_you(text): tts('I am fine, thank you.')
def are_you_up(text): tts('For you sir, always.')
def spell_text(text): text = list(text.split(' ', 1)[1]) spelling = ' '.join(text) tts(spelling)
def marry_me(text): tts('I have been receiving a lot of marriage proposals recently.')
def news_reader(text): for key, value in news_dictionary.items(): tts('Headline, ' + key) tts('News, ' + value)
def repeat_text(text): text = text.split(' ', 1)[1] tts(text)
def tell_horoscope(text): tts(HoroscopeGenerator.format_sentence(HoroscopeGenerator.get_sentence()))