Esempio n. 1
0
def database():
    path = os.getcwd() + "/Text_Files/corpora.txt"
    f_corpora = open(path, "r")
    data = []
    nltk_info_path = os.getcwd() + "/Text_Files/nltk_data_path.txt"
    nltk_info_path_os = nltk_info_path.replace(" ", "\ ")
    nltk_info_path_os = nltk_info_path_os.replace("(", "\(")
    nltk_info_path_os = nltk_info_path_os.replace(")", "\)")
    if os.path.isfile(
            nltk_info_path_os) == False:  #Checks if nltk_data_path.txt exists.
        f_nltk = open(nltk_info_path, "w")
        os.system('find / -iname "nltk_data" 2>/dev/null>' + nltk_info_path_os)
        if os.stat(nltk_info_path).st_size == 0:
            speak("Please install NTLK. I can't run until then. Goodbye.")
        else:
            f_nltk.close()

    f_nltk = open(os.getcwd() + "/Text_Files/nltk_data_path.txt", "r")
    nltk_data_path = f_nltk.readline().strip()
    f_nltk.close()

    for name in f_corpora:
        f = open(nltk_data_path + "/corpora/gutenberg/" + name.strip())
        f.seek(0)
        data_temp = f.read()
        data = data + data_temp.split()
        del data_temp
        f.close()

    f_corpora.close()
    return data
Esempio n. 2
0
def ping():
    """
    Checks for an Internet connection.
    If success, saves "success" in the file mentioned below.
    Else, saves "failure".
    """
    path = os.getcwd() + "/Text_Files/ping_result.txt"
    path_os = path.replace(" ", "\ ")
    path_os = path_os.replace("(", "\(")
    path_os = path_os.replace(")", "\)")
    os.system('guake -n CUR_DIR -e "if ! ping -c 1 '
              'www.google.com &>/dev/null;'
              'then echo fail >' + path_os + ';'
              'else echo success>' + path_os + ';fi;clear"')
    os.system("guake -s 1")
    os.system("guake -s 2 -e exit")

    f_ping = open(path)
    result = f_ping.read().strip().split("\n")
    result = ''.join(result)
    f_ping.close()
    if result == 'success':
        return 1
    else:
        speak("Sorry. Internet is down currently.")
        return 0
Esempio n. 3
0
def check_reminder():
    """
    Checks if you have any reminder set for today.
    """
    current_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    c_year = current_date[0:4]
    c_month = current_date[5:7]
    c_date = current_date[8:10]
    to_del = ''
    reminder_path = os.getcwd() + "/Text_Files/reminder.txt"
    f_reminder = open(reminder_path, "r+")
    for line in f_reminder:
        r_date = line[0:2]
        if r_date == c_date:
            r_month = line[3:5]
            if r_month == c_month:
                r_year = line[6:10]
                if r_year == c_year:
                    speak("You have a reminder set for today." \
                        "This is what it says: \n" + line[11:])
                    speak("Would you like me to delete the reminder now?")
                    reply = raw_input('\033[1m' + 'Username ' +
                                      '\033[0m')  #modify
                    if confirm(reply) == 1:
                        to_del = line
                        #TO FINISH
    f_reminder.close()
Esempio n. 4
0
def check_last_update():
    """
    Checks when the system was last updated.
    If the system was not updated for the last 2 days, updates system.
    """
    update_path = os.getcwd() + "/Text_Files/prev_update.txt"
    f_update = open(update_path, 'r+')
    prev_date = f_update.read().strip().split("/")
    current_date = time.strftime("%d/%m/%Y")
    date = current_date.strip().split("/")
    if (int(date[0])-int(prev_date[0]) > 2) or \
        (int(date[1])-int(prev_date[1]) > 0) or \
        (int(date[2])-int(prev_date[2]) > 0):
        if ping() == 1:
            speak("Hey, I just realised that it's been a while that " \
                "your system has been updated.")
            speak("Would you like to update system now?")
            reply = raw_input('\033[1m' + 'Username: '******'\033[0m')  #modify
            if confirm(reply) == 1:
                speak("Please input password to update system.")
                os.system("sudo apt-get update && apt-get upgrade")
                f_update.seek(0)
                f_update.write(current_date)
                f_update.truncate()
                speak("System successfully updated.")
        else:
            speak("It's been a while since your system has been updated. " \
                "I can't update it now, since Internet is down.")
    f_update.close()
Esempio n. 5
0
def reminder ():
	"""
	Initialises the reminder.
	"""
	speak("You want to: set a new reminder, read reminder, or delete reminder? Type 'q' to quit.")
	speak("Input Set or Read or Delete or q.")
	#inpt = (input('\033[1m'+'Username: '******'Harshit')).lower()	
	listen()
Esempio n. 6
0
def fn_close_tab():
    """
    Closes a firefox tab.
    """
    speak('Do you want me to close the current tab?')
    reply = raw_input('\033[1m' + 'Username: '******'\033[0m')  #modify: Change "Username"
    if confirm(reply) == 1:
        os.system('wmctrl -a firefox; xdotool key Ctrl+w;')
    else:
        speak('Ok')
        return
Esempio n. 7
0
def terminal():
    """
    Opens the terminal.
    """
    speak("You are into the terminal now."
        "Type 'exit' when you want to quit.")
    while True:
        command = raw_input('\033[1m' + 'Username: '******'\033[0m')   #modify
        if command.lower() == "exit":
            speak("Quit terminal.")
            return
        else:
            os.system(command)
Esempio n. 8
0
def fn_movie(name):
    """
    Searches for the movie name in 2 paths.

    If movie is found, plays with vlc.
    """
    path_list = ["/path1/", "/path2" "/path3/"]  #modify
    for path in path_list:
        os.system('find ' + path + ' -iname "*' + name + '*"'
                  ' -exec vlc --fullscreen {} + & >/dev/null;')
    os.system("clear")
    speak("Hope you enjoy the movie!!!")
    os.system("clear")
Esempio n. 9
0
def sophie(string):

    #Splitting each sentence in a list of words.
    word_list = word_tokenize(string)

    #Setting up stop_words: words that are redundant.
    stop_words = set(stopwords.words('german'))

    #Creating space for a list of sentences without stop_words.
    if "search" not in word_list and "google" not in word_list and "say" not in word_list:
        filtered_sentence = [w for w in word_list if not w in stop_words]
    else:
        filtered_sentence = [w for w in word_list]

    if "hallo" in filtered_sentence:
        speak("Hallo!")

    elif "tschüss" in filtered_sentence:
        speak("Bis dann!")
        quit()

    elif "time" in filtered_sentence:
        print(time.ctime())

    elif "sag" in filtered_sentence:
        output = ' '.join(word_list[1:])
        speak(output)

    elif "wie geht es dir" in string:
        speak('Mir geht es gut!')

    elif "how much is the fish" in string:
        os.system("mpg123 -q howmuchisthefish.mp3")

    return None
Esempio n. 10
0
def fn_read_mail():
    """
    Checks how many unread mails are there in the inbox.
    """
    if ping() == 0:
        speak("Sorry. The Internet is down currently.")
        return
    os.system("/path/to/the/file/check_email.sh")  #modify
    inbox_path = os.getcwd() + "/Text_Files/inbox_details.txt"
    f_inbx = open(inbox_path)
    data = f_inbx.read()
    f_inbx.close()
    unread_mails = int(data[(data.index("<fullcount>") + 11)\
  :data.index("</fullcount>")])
    speak("You have " + str(unread_mails) + " unread mails.")
def hear():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Speak:")
        audio = r.listen(source)
    data = ""
    try:
        data = r.recognize_google(audio)
        print("You said: " + data)
    except sr.UnknownValueError:
        speak("I am sorry, I did not understand. Could you repeat it again?")
        return "error"
    except sr.RequestError as e:
        speak("I am sorry, I did not understand. Could you repeat it again?")
        return "error"

    return data
Esempio n. 12
0
def fn_open_site(site):
    """
    Opens a website on the firefox browswer.
    """
    if ping() == 0:
        speak("Sorry. Internet is down currently.")
        return
    if site.endswith(".com") == True:
        os.system('guake -n CUR_DIR -e "firefox "' + site + '" & >/dev/null"')
        speak("Please give me a while to complete the task.")
        os.system("guake -s 1")
        os.system("guake -s 2 -e exit")
        speak("Task successfully completed.")

    else:
        os.system('guake -n CUR_DIR -e "firefox "' + site +
                  '".com & >/dev/null"')
        speak("Please give me a while.")
        os.system("guake -s 1")
        os.system("guake -s 2 -e exit")
        speak("Task successfully completed.")
Esempio n. 13
0
def open_folder(name):
    """
    Checks if a folder with the given name exists in directory.
    If yes, opens it.
    """
    name = name.strip()
    #os.system("find -type d -iname '*"+name +"*' -exec xdg-open ")
    counter = 0
    path_1 = os.getcwd() + "/Text_Files/folder.txt"
    f_fldr = open(path_1, "r")
    for line in f_fldr:
        name_list = line.strip().split("-")
        if name.lower() == ''.join(name_list[0:1]).lower():
            counter = 1
            path = ''.join(name_list[1:2])
            os.system('xdg-open ' + path)
            speak("Opened the requested folder.")
            break
    f_fldr.close()
    if counter == 0:
        speak("Sorry, but I could not find the folder.")
Esempio n. 14
0
def delete_rm():
	"""
	Deletes reminder.
	"""
	speak("Here are the reminders:")
	reminder_path = os.getcwd() + "/Text_Files/reminder.txt"
	f = open(reminder_path, "r+")	
	data = []
	for line in f:
		print line
		data.append(line)
	raw_input()
	speak('Please enter the date of the reminder in the following format: ')
	print "dd/mm/yyyy"
	reminder_date = raw_input('\033[1m'+'Username: '******'\033[0m')	#modify
	while verify_date(reminder_date) == False:
		speak("Sorry, invalid input. Try again")
		reminder_date = raw_input('\033[1m' + 'Username: '******'\033[0m')	#modify
	
	new_data = []
	for line in data:
		if reminder_date in line:
			continue
		new_data.append(line)
	f.seek(0)
	f.writelines([line for line in new_data])			
	f.truncate()
	f.close()
Esempio n. 15
0
def set_rm():
	"""
	Sets reminder.
	"""
	speak("Please enter the date of the reminder in the following format: ")
	print "dd/mm/yyyy"
	reminder_date = raw_input('\033[1m'+'Username: '******'\033[0m')	#modify
	
	while verify_date(reminder_date) == False:
		speak("Sorry, invalid input. Try again")
		reminder_date = raw_input('\033[1m'+'Username: '******'\033[0m') #modify
	speak("Now set the reminder.")
	reminder_text = raw_input('\033[1m'+'Username: '******'\033[0m')	#modify
	reminder_path = os.getcwd() + "/Text_Files/reminder.txt"
	with open(reminder_path, "a") as f_reminder:		
		f_reminder.write(reminder_date + " - " + reminder_text + "\n")
	f_reminder.close()
	
	speak("Reminder successfully set.")
Esempio n. 16
0
def main():

    """
    Greets the user.
    Checks when the system was last updated.
    Checks if there are reminders.
    Waits for user input.
    If input is "bye" (or similar), quits.
    Else passes the user input to the function tzara() stored in tzara.py
    """

    greetings_path = os.getcwd() + "/Text_Files/greetings.txt"
    f_greetings = open(greetings_path, "r")  
    greetings_list = f_greetings.read().strip().split("\n")
    f_greetings.close()

    bye_path = os.getcwd() + "/Text_Files/bye.txt"
    f_bye = open(bye_path, "r")  
    bye_list = f_bye.read().strip().split("\n")
    f_bye.close()
    bye_list2 = [''.join(bye_list[i])+" tzara" for i in range(0, len(bye_list))]
    bye_list3 = [''.join(bye_list[i])+" then" for i in range(0, len(bye_list))]

    random_greeting = random.randrange(0, len(greetings_list))
    speak(greetings_list[random_greeting])

    check_last_update()
    check_reminder()
    

    while 1:
        input_string = raw_input('\033[1m'+'Ask me something: '+'\033[0m')  #modify
        if input_string:
            input_string = input_string.lower()
            if input_string in bye_list or \
                input_string in bye_list2 or \
                input_string in bye_list3:
                time_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                if int(time_now[11:13]) > 20 or int(time_now[11:13]) < 4:
                    speak("Goodnight.")
                else:
                    speak('See you later then! Have a good day!')
                return
            tzara(input_string)
Esempio n. 17
0
def reminder ():
	"""
	Initialises the reminder.
	"""
	speak("You want to: set a new reminder, read reminder, or delete reminder? Type 'q' to quit.")
	speak("Input Set or Read or Delete or q.")
	inpt = (raw_input('\033[1m'+'Username: '******'\033[0m')).lower()	#modify
	
	while verify_input(INPUT) == False:
		speak("Input Set or Read or Delete or q.")
		inpt = raw_input('\033[1m'+'Username: '******'\033[0m').lower()	#modify
	
	if inpt == "set":
		set_rm()		
	elif inpt == 'read':
		read_rm()		
	elif inpt == 'delete':
		delete_rm()	
	else: return
Esempio n. 18
0
def fn_search(word):
    """
    Calls ping().
    If success:
        Searches for the given sentence.
    """

    if ping() == 0:
        return
    speak('Would you like me to search for "' + word + '"?')
    reply = raw_input('\033[1m' + 'Username: '******'\033[0m')  #modify: Change "Username"
    if confirm(reply) == 1:
        word = word.replace(" ", "+")
        search_link = "www.google.co.in/#q=" + word
        speak('Cool. Here are the results.')
        os.system('guake -n CUR_DIR -e "firefox "' + search_link +
                  '" & >/dev/null"')
        os.system("guake -s 1")
        os.system("guake -s 2 -e exit")
        return
    else:
        speak("As you wish.")
        return
def game():
    # set the list of words, maxnumber of guesses, and prompt limit
    WORDS = ["apple", "banana", "orange", "mango", "lemon"]
    NUM_GUESSES = 3
    PROMPT_LIMIT = 5

    # get a random word from the list
    word = random.choice(WORDS)

    # format the instructions string
    instructions = ("I'm thinking of one of these words:\n"
                    "{words}\n"
                    "You have {n} tries to guess which one.\n").format(
                        words=', '.join(WORDS), n=NUM_GUESSES)

    # show instructions and wait 3 seconds before starting the game
    speak(instructions)
    #time.sleep(3)

    for i in range(NUM_GUESSES):
        # get the guess from the user
        # if a transcription is returned, break out of the loop and
        #     continue
        # if no transcription returned and API request failed, break
        #     loop and continue
        # if API request succeeded but no transcription was returned,
        #     re-prompt the user to say their guess again. Do this up
        #     to PROMPT_LIMIT times
        for j in range(PROMPT_LIMIT):
            st = 'Guess {}. Speak!'.format(i + 1)
            speak(st)

            guess = hear()
            if guess != "error":
                speak("You said: {}".format(guess))
                # determine if guess is correct and if any attempts remain
                guess_is_correct = guess.lower() == word.lower()
                user_has_more_attempts = i < NUM_GUESSES - 1
                break
            else:
                speak("Let's hear it again.")

        # determine if the user has won the game
        # if not, repeat the loop if user has more attempts
        # if no attempts left, the user loses the game
        if guess_is_correct:
            st = "Correct! You win!" + word
            speak(st)
            break
        elif user_has_more_attempts:
            speak("Incorrect. Try again.")
        else:
            st = "Sorry, you lose! I was thinking of '" + word + "'"
            speak(st)
            break
Esempio n. 20
0
def fn_close_movie():
    """
    Kills vlc
    """
    os.system("killall vlc")
    speak("Job's done.")
Esempio n. 21
0
from Speech import speak

speak("How are you")
Esempio n. 22
0
def tzara(string):
    """
    Searches the input string for keywords, or commands.
    If keywords are found, it calls appropriate function.
    List of functions:
    (1) Open (website, pdf, folder, terminal, reminder)
    (2) Play (movies, songs)
    (3) Tell the time.
    (4) Google, or search for a string online.
    (5) Close (tab, song, movie, pdf)
    (6) Mail (read, send)
    (7) Shutdown
    (8) Reminder
    """
    #Splitting each sentence in a list of words.
    word_list = word_tokenize(string)

    #Setting up stop_words: words that are redundant.
    stop_words = set(stopwords.words('english'))

    #Creating space for a list of sentences without stop_words.
    if "search" not in word_list and "google" not in word_list:
        filtered_sentence = [w for w in word_list if not w in stop_words]
    else:
		filtered_sentence = [w for w in word_list]
   
    if 'open' in filtered_sentence:
        #OPEN WEBSITE
        if 'site' in filtered_sentence:
            print "in function"
            filtered_sentence = [w for w in filtered_sentence \
                if w != "called" and w != "named"]
            firefox.fn_open_site( \
                filtered_sentence[filtered_sentence.index('site') + 1])
        elif 'website' in filtered_sentence and \
            filtered_sentence.index('open') \
                < filtered_sentence.index('website'):
            firefox.fn_open_site( \
                filtered_sentence[filtered_sentence.index('website') + 1])

        #OPEN PDF
        elif 'pdf' in filtered_sentence and \
            filtered_sentence.index('open') \
                < filtered_sentence.index('pdf'):
            filtered_sentence = \
                [w for w in filtered_sentence \
                    if w != "called" and w != "named"]
            fn_open_pdf(filtered_sentence[filtered_sentence.index('pdf') + 1])

        #OPEN FOLDER
        elif 'folder' in filtered_sentence and \
            filtered_sentence.index('open') \
                < filtered_sentence.index('folder'):
            if "called" in string:
                pos = string.index("called") + 7
                string = string[pos:]
            elif "named" in string:
                pos = string.index("named") + 6
                string = string[pos:]
            else:
                pos = string.index("folder")+7
                string = string[pos:]
            open_folder(string)

       #OPEN TERMINAL
        elif 'terminal' in filtered_sentence and \
            filtered_sentence.index('open') \
            < filtered_sentence.index('terminal'):
            terminal.terminal()

        #OPEN REMINDER
        elif 'reminder' in filtered_sentence:
            reminder.reminder()

        elif len(filtered_sentence) > 1:
            sites_path = os.getcwd() + "/Text_Files/comn_sites.txt"
            f_sites = open(sites_path, "r")     
            for line in f_sites:
                name_list = line.strip().split("-")
                #if (n.lower()==''.join(name_list[0:1]).lower()):
                #    counter=1
                #    email_id=''.join(name_list[1:2])
                pos = filtered_sentence.index('open')+1
                if ''.join(filtered_sentence[pos]).lower() \
                    in ''.join(name_list[0:1]).lower():
                    print ''.join(name_list[1:2])
                    firefox.fn_open_site(''.join(name_list[1:2]))
            f_sites.close()

        else:
            speak("You want me to open something,"
                "but I'm not sure what. Could you please repeat?")

    elif 'terminal' in filtered_sentence:
        speak("Would you like me to open the terminal for you?")
        reply = raw_input('\033[1m'+'Username: '******'\033[0m') #modify
        if confirm(reply) == 1:
            terminal.terminal()
        else:
            speak("As you wish.")

    elif 'movie' in filtered_sentence:
        #PLAY MOVIE
        filtered_sentence = [w for w in filtered_sentence \
            if w != "called" and w != "named" and w != "titled"]
        pos = filtered_sentence.index('movie') + 1
        fn_movie(filtered_sentence[pos])

        #PLAY SONG
    elif 'song' in filtered_sentence and filtered_sentence.index('play') \
        < filtered_sentence.index('song'):
        filtered_sentence = [w for w in filtered_sentence \
            if w != "called" and w != "named" and w != "titled"]
        pos = filtered_sentence.index('song') + 1
        fn_play_song(filtered_sentence[pos])

    elif 'time' in filtered_sentence:
        speak(time.strftime("%A") + " " \
            + str(datetime.datetime.now())[:16])

    elif 'google' in filtered_sentence:
        if len(filtered_sentence) > 1:
            pos = filtered_sentence.index('google') + 1
            if 'word' in filtered_sentence \
                and filtered_sentence[-1] != 'word':
                filtered_sentence = \
                    [w for w in filtered_sentence if w != "word"]

            search_string = ''.join(filtered_sentence[pos:])
            firefox.fn_search(search_string)
        else:
            speak("If you want me to open google, say 'open google'")
            speak("If you want me to search for a word,"
                "say 'google <word>'")

    elif 'search' in filtered_sentence:
        if filtered_sentence[-1] == "search":
            speak("Enter the word you would like me to search.")
            search_string = raw_input('\033[1m' + 'Username: '******'\033[0m')     #modify
            firefox.fn_search(search_string)
            return
        pos = filtered_sentence.index('search') + 1
        search_string = " ".join(filtered_sentence[pos:])
        firefox.fn_search(search_string)

    elif 'reminder' in filtered_sentence:
        speak("Opening reminder")
        reminder.reminder()

    elif 'close' in filtered_sentence:
        if 'tab' in filtered_sentence:
            firefox.fn_close_tab()
            speak('There you go!')
        if 'song' in filtered_sentence:
            fn_close_song()
        if 'movie' in filtered_sentence:
            fn_close_movie()
        if 'pdf' in filtered_sentence:
            fn_close_pdf()
        else:
            speak("I figure you want me to close something,"
                "but I'm not sure what!")

    elif 'ping' in filtered_sentence:
        firefox.ping()

    elif 'mail' in filtered_sentence:
        if 'read' in filtered_sentence or \
            'unread' in filtered_sentence or \
            'check' in filtered_sentence or \
            'see' in filtered_sentence:
            firefox.fn_read_mail()
        elif filtered_sentence[-1] != 'mail':
            pos = filtered_sentence.index('mail') + 1
            firefox.fn_write_mail(filtered_sentence[pos])
        elif filtered_sentence[-1] == 'mail':
            speak("Whom would you like to mail?")
            reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify
            firefox.fn_write_mail(reply)
        else:
            speak("Do you want to mail somebody?"
                " Then type: 'mail person's_name'")
            speak("Or do you want to read your emails?"
                "Then simply type: 'read mail'")

    elif 'shutdown' in filtered_sentence:
        speak("Would you like me to shutdown the system?")
        reply = raw_input('\033[1m' + 'Username: '******'\033[0m')     #modify
        if confirm(reply) == 1:
            speak("Shutting down system now. Goodbye!")
            os.system("sudo shutdown -h now")
        else:
            speak("As you wish.")

    else:
        speak(converse(string))
    return None
            pos = filtered_sentence.index('google') + 1
            if 'word' in filtered_sentence \
                and filtered_sentence[-1] != 'word':
                filtered_sentence = \
                    [w for w in filtered_sentence if w != "word"]

            search_string = ''.join(filtered_sentence[pos:])
            firefox.fn_search(search_string)
        else:
            speak("If you want me to open google, say 'open google'")
            speak("If you want me to search for a word,"
                "say 'google <word>'")

   elif 'search' in filtered_sentence:
        if filtered_sentence[-1] == "search":
            speak("Enter the word you would like me to search.")
            search_string = raw_input('\033[1m' + 'Username: '******'\033[0m')     #modify
            firefox.fn_search(search_string)
            return
        pos = filtered_sentence.index('search') + 1
        search_string = " ".join(filtered_sentence[pos:])
        firefox.fn_search(search_string)

    elif 'reminder' in filtered_sentence:
        speak("Opening reminder")
        reminder.reminder()

    elif 'close' in filtered_sentence:
        if 'tab' in filtered_sentence:
            firefox.fn_close_tab()
            speak('There you go!')
def cadbury(data):
    """
    Searches the input string for keywords, or commands.
    If keywords are found, it calls appropriate function.
    List of functions:
    (1) Open maps for a place
    (2) Play Game
    (3) Tell the time.
    (4) Google, or search for a string online.
    (5) Open Google
    (6) Play Song on Youtube
    (7) Reading News feed 
    """
    #Splitting each sentence in a list of words.
    word_list = word_tokenize(data)

    #Setting up stop_words: words that are redundant.
    stop_words = set(stopwords.words('english'))

    #Creating space for a list of sentences without stop_words.
    if "search" not in word_list and "google" not in word_list and "Search" not in word_list and "Google" not in word_list:
        filtered_sentence = [w for w in word_list if not w in stop_words]
    else:
        filtered_sentence = [w for w in word_list]

    if ("bored" in filtered_sentence):
        speak("Let's play a game then!!")
        game()
    elif 'time' in filtered_sentence:
        speak(time.strftime("%A") + " " + str(datetime.datetime.now())[:16])
    elif 'song' in filtered_sentence and filtered_sentence.index(
            'play') < filtered_sentence.index('song'):
        filtered_sentence = [
            w for w in filtered_sentence
            if w != "called" and w != "named" and w != "titled"
        ]
        pos = filtered_sentence.index('song') + 1
        speak("Opening Youtube Searches for {}".format(filtered_sentence[pos]))
        playSong(filtered_sentence[pos])
    elif 'game' in filtered_sentence and filtered_sentence.index(
            'play') < filtered_sentence.index('game'):
        game()
    elif 'google' in filtered_sentence or "Google" in filtered_sentence:
        if len(filtered_sentence) > 1:
            if 'open' in filtered_sentence and 'google' in filtered_sentence and filtered_sentence.index(
                    'open') < filtered_sentence.index('google'):
                google()
            if 'open' in filtered_sentence and 'Google' in filtered_sentence and filtered_sentence.index(
                    'open') < filtered_sentence.index('Google'):
                google()
            else:
                pos = 0
                if 'google' in filtered_sentence:
                    pos = filtered_sentence.index('google') + 1
                elif 'Google' in filtered_sentence:
                    pos = filtered_sentence.index('Google') + 1
                if 'word' in filtered_sentence and filtered_sentence[
                        -1] != 'word':
                    filtered_sentence = [
                        w for w in filtered_sentence if w != "word"
                    ]

                search_string = ''.join(filtered_sentence[pos:])
                google_search(search_string)
        else:
            speak("If you want me to open google, say 'open google'")
            speak("If you want me to search for a word," "say 'google <word>'")
    elif 'search' in filtered_sentence:
        if filtered_sentence[-1] == "search":
            speak("What would you like me to search?")
            for j in range(5):
                search_string = hear()
                if (search_string != 'error'):
                    google_search(search_string)
                    break
            return None
        pos = filtered_sentence.index('search') + 1
        search_string = " ".join(filtered_sentence[pos:])
        google_search(search_string)
    elif 'location' in filtered_sentence:
        if filtered_sentence[-1] == "location":
            speak("What place should I look for?")
            for j in range(5):
                location = hear()
                if (location != "error"):
                    maps(location)
                    break
            return None

        pos = filtered_sentence.index('location') + 1
        loc = "".join(filtered_sentence[pos:])
        maps(loc)
    elif 'news' in filtered_sentence:
        speak("Here are the top 5 stories for you.")
        NewsFeed = feedparser.parse(
            "https://timesofindia.indiatimes.com/rssfeedstopstories.cms")
        for j in range(5):
            entry = NewsFeed.entries[j]
            speak("Number {}".format(j + 1))
            speak(entry.title)
            speak(entry.summary)
            print("=======================================")
    else:
        speak("I am not aware of this command. Could you try something else?")
    return None
def main():
    time.sleep(2)
    speak("Hello! What can I do for you today?")
    while 1:
        data = hear()
        exit_flag = 0
        #data = input();
        if data!="" and data!="error":
            if "bye" in data:
                speak("Bye, Have a great day!")
                break
            if "cadbury"==data or "Cadbury"== data:
                speak("Yes right! That's my name. Tell me how may I help you?")
            else:
                cadbury(data)
                time.sleep(5)
                speak("Do you have any other commands?")
                for j in range(5):
                    confirm = hear()
                    if "error" not in confirm and "yes" not in confirm:
                        exit_flag=1
                        break
                    elif "yes" in confirm:
                        exit_flag=0
                        break
                if exit_flag == 1:
                    speak("Okay then. My work here is done. Have a good day!!")
                    break
                else:
                    speak("Great!!What can I do for you next?")
Esempio n. 26
0
def fn_write_mail(name):
    """
    If an Internet connection is there:
        Checks if the given name exists in directory.
        If it does, asks user to write the mail, then send.
        Else, asks for a valid email-id. Then asks the user to write.
    Else quits.
    """
    if ping() == 0:
        speak("Sorry. The Internet is down currently.")
        return
    counter = 0
    email_path = os.getcwd() + "/Text_Files/email_id.txt"
    f_email = open(email_path)
    for line in f_email:
        print line
        name_list = line.strip().split("-")
        if name.lower() == ''.join(name_list[0:1]).lower():
            counter = 1
            email_id = ''.join(name_list[1:2])
            speak("Now write the mail. Press Control+D when you are done.")
            os.system('mail ' + email_id)
            speak("The mail has been sent.")
            break
    f_email.close()
    if counter == 0:
        speak("Sorry. The name doesn't exist in the directory."
              "You'll have to give me the person's email address"
              " for me to mail him. Would you like to do that?")
        reply = raw_input('\033[1m' + 'Username: '******'\033[0m')  #modify: Change "Username"
        if confirm(reply) == 1:
            speak("Ok. Now please enter a valid email address.")
            email_id = raw_input('\033[1m' + 'Username: '******'\033[0m')  #modify: Change "Username"
            speak("Now write the mail. " "Press Control+D when you are done.")
            os.system('mail ' + email_id)
            speak("The mail has been sent.")

        else:
            speak("As you wish.")
Esempio n. 27
0
def fn_open_pdf(name):
    """
    Opens the pdf using evince.
    """
    os.system('find -iname "*' + name + '*.pdf" -exec evince {} + &disown\;')
    speak("There you go! Enjoy reading!")
Esempio n. 28
0
def fn_close_pdf():
    """
    Kills evince.
    """
    speak("Closing PDF.")
    os.system("killall evince")