示例#1
1
文件: todo_action.py 项目: i-am-Q/AVA
            my_file = open(config.todo_loc, 'w')
            my_file.close()
            my_file = open(config.todo_loc, 'r')
        f = my_file.readlines()
        my_file.close()
        y = 0
        f2 = f
        for n in f:
            y += 1
            f2[y - 1] = str(y) + ': ' + f[y - 1] + '\n'
        f_readable = ''.join(f2)
        x = len(f)
        if x == 1:
            text1 = 'you have one item on your list'
            text = text1 + 'and it is:' + f_readable
        elif x > 1:
            text1 = 'you have %s items on your list' % x
            text = text1 + ' and they are:\n' + f_readable
        else:
            text = 'you have zero items on your list'
        talking(text)
        talking('Would you like me to send this to your email?')
        i_said = listening()
        key = ['yes', 'no']
        a = pre_selection(i_said, key)
        if a == [0]:
            talking('preparing your todo list to be sent')
            send_email(text, 'ToDo List')
        elif a == [1]:
            pass
示例#2
0
文件: todo_action.py 项目: i-am-Q/AVA
def todo(action):
    """
    talking('would you like to add to your to do list or clear it')
    key = ['add','clear','ad']
    i_said = listening()
    a = pre_selection(i_said, key)
    print a"""

# prints todo list
    if action == [11, 12]:
        the_start = True
        while the_start:
            try:
                my_file = open(config.todo_loc, 'r')
            except IOError:
                print 'No ToDo list exists, creating a new file'
                my_file = open(config.todo_loc, 'w')
                my_file.close()
                my_file = open(config.todo_loc, 'r')
            f = my_file.readlines()
            my_file.close()
            talking('what would you like to add to your list')
            while True:
                try:
                    i_said = listening()
                    f.insert(0, i_said + '\n')
                    break
                except TypeError, e:
                    print e
                    print 'nothing was said'
            my_file = open(config.todo_loc, 'w')
            my_file.writelines(f)
            my_file.close()
            talking('your task has been added, would you like to add more')
            try:
                i_said = listening()
                key = ['yes', 'ad', 'add', 'more', 'done', 'no', 'finished']
                find_truth = pre_selection(i_said, key)
                for num in find_truth:
                    print find_truth
                    yes_test = [0, 1, 2, 3]
                    no_test = [4, 5, 6]
                    a = num in yes_test
                    if a:
                        for num2 in find_truth:
                            b = num2 in no_test
                            if b:
                                the_start = False
                            else:
                                print 'adding more'
                    elif not a:
                        for num2 in find_truth:
                            b = num2 in no_test
                            if b:
                                the_start = False
            except TypeError, e:
                the_start = False
                print e
                break
示例#3
0
文件: games.py 项目: i-am-Q/AVA
def play_hi_low():
    play_again = True

    while play_again:
        cont = True
        num_guess = 0
        comp_num = randint(1, 10)
        print comp_num
        talking('I have picked a number between one and ten. Can you guess what it is?')
        while True:
            player_guess = listening()
            # checks for the number 6 (has difficulty understanding difference between 6 and sex)
            if player_guess == 'sex':
                player_guess = '6'
            # checks for the number 4 (has difficulty understanding difference between 4 and thor)
            if player_guess == 'thor':
                player_guess = '4'
            try:
                player_guess = int(player_guess)
            except (ValueError, TypeError), e:
                print e
            if player_guess == comp_num:
                num_guess += 1
                text = 'Congratulations! You won in %i guesses!' % num_guess
                talking(text)
                talking('Do you want to play again. Yes or no?')
                i_said = listening()
                key = ['yes', 'no', 'quit']
                redo = pre_selection(i_said, key)
                while cont:
                    if redo == [0]:
                        cont = False
                        break
                    elif (redo == [1, 2]) or (redo == [1]) or (redo == [2]):  # if anything else is said, assume a quit
                        play_again = False
                        cont = False
                        break
                    else:
                        talking('I am sorry. please say either yes or no')
                        break
                break
            elif player_guess < comp_num:
                talking('Guess higher')
                num_guess += 1
            elif player_guess > comp_num:
                talking('Guess lower')
                num_guess += 1
示例#4
0
文件: games.py 项目: i-am-Q/AVA
    def __init__(self):
        comp_score = 0
        player_score = 0
        tie_game = 0
        player = 0
        playing = True
        validity = True
        talking('Lets play a game of Rock, Paper, Scissors')
        while playing:
            while validity:
                i_said = listening()
                bro_commands = ['rock', 'paper', 'scissors', 'quit', 'Rock']
                player_hand = pre_selection(i_said, bro_commands)
                if (player_hand == [0]) or (player_hand == [4]):
                    player = 1
                    break
                elif player_hand == [1]:
                    player = 2
                    break
                elif player_hand == [2]:
                    player = 3
                    break
                elif player_hand == [3]:
                    player = 4
                    break
                else:
                    print 'Invalid Choice'
            if player == 4:
                if player_score > comp_score:
                    text = 'final score, player %i, computer %i, Congratulations you win' % (player_score, comp_score)
                elif player_score < comp_score:
                    text = 'final score, player %i, computer %i, Computer wins' % (player_score, comp_score)
                else:
                    text = 'final score, player %i, computer %i, tie game' % (player_score, comp_score)
                talking(text)
                break

            else:
                comp = self.comp_hand()
                result = self.play_hand(comp, player)
                player_choice = self.interpret(player)
                comp_choice = self.interpret(comp)
                print '\nYou played %s and the computer played %s' % (player_choice, comp_choice)
                talking(result)
                print ''
                print '-' * 34
                if result == 'Computer wins!':
                    comp_score += 1
                elif result == 'Player wins!':
                    player_score += 1
                elif result == 'Tie game':
                    tie_game += 1
                print 'Player: %i Computer: %i Tie Games: %i' % (player_score, comp_score, tie_game)
                print '-' * 34
                print ''
示例#5
0
文件: mainLogic.py 项目: i-am-Q/AVA
def wake_up(what_thread):
    print 'thread %s has started' % what_thread
    while True:
        menus.menu_intro()
        i_said = listening()
        key = config.my_name
        i_said = i_said.replace('what\'s','what is')
        find_truth = pre_selection(i_said, key)
        if find_truth == [0]:
            selection(i_said)
        else:
            menus.menu_choice()
            print 'no selection made'
示例#6
0
文件: knowledge.py 项目: i-am-Q/AVA
def wolfram_alpha(my_question):

    searching = True
    search_item = 0
    some_text = None

    look_for = my_question
    talking('let me think')
    key = config.wolf_key
    my_question = my_question.replace('ava ', '')
    my_question = my_question.replace(' ', '+')
    print my_question
    url = 'http://api.wolframalpha.com/v2/query?appid=' + key + '&input=' + my_question + '&format=plaintext'

    tree = ET.ElementTree(file=urllib.urlopen(url))
    for elem in tree.iterfind('pod[@title="Result"]/subpod/plaintext'):
        some_text = elem.text
    try:
        some_text = some_text.replace('\'', ' feet')
        some_text = some_text.replace('\"', ' inches')
        talking(some_text)
        time.sleep(1)
    except Exception, e:
        print e
        pattern = re.compile('([^\s\w]|_)+')
        b_string = re.sub(pattern, '', look_for)
        phrase = b_string
        print phrase
        pattern = re.compile("\\b(lot|lots|a|an|who|can|you|what|is|info|somethings|whats|have|i|something|to|know|like"
                             "|Id|information|about|tell|me)\\W", re.I)
        phrase_noise_removed = [pattern.sub("", phrase)]
        print phrase_noise_removed[0]
        term_search = wikipedia.search(phrase_noise_removed[0])
        # ToDo: test this portion. It checks to see if what AVA is searching for is the correct thing
        while searching:
            text = 'would you like me to get information on %s' % term_search[search_item]
            talking(text)
            rsp = listening()
            my_rsp = comprehension.pre_selection(rsp, ['yes', 'no'])
            if (my_rsp == [0]) and (search_item <= 2):
                print term_search[search_item]
                the_summary = (wikipedia.summary(term_search[search_item], 2))
                print the_summary
                talking(the_summary)
                searching = False
            elif my_rsp == [1]:
                talking('ok')
                search_item += 1
示例#7
0
文件: mainLogic.py 项目: i-am-Q/AVA
def selection(what_i_said):
    find_truth = pre_selection(what_i_said, slct)
    if not find_truth:
        talking('How can I help you sir')
        menus.menu_choice()
        what_i_said = listening()
        what_i_said = what_i_said.replace('what\'s','what is')
        find_truth = pre_selection(what_i_said, slct)
        print find_truth
    while True:

        if (find_truth == [0, 1]) or (find_truth == [15]):
            games.play_hi_low()
            break
        elif find_truth == [2]:
            break
        elif (find_truth == [3, 4, 16, 17]) or (find_truth == [4, 9, 16, 17]) or (find_truth == [3, 4, 9, 16, 17]) \
                or (find_truth == [3, 4]) or (find_truth == [4, 9]) or (find_truth == [3, 4, 9]):
            weather.current_weather()
            break
        elif (find_truth == [4, 5]) or (find_truth == [5]) or (find_truth == [4, 5, 16, 17]) or \
                (find_truth == [4, 16, 17]):
            weather.forecast()
            break
        elif find_truth == [6, 7, 8]:
            games.RPSGame()
            break
        elif find_truth == [10]:
            games.tell_joke()
            break
        elif (find_truth == [11, 12]) or (find_truth == [11, 13]) or (find_truth == [11, 14]):
            todo_action.todo(find_truth)
            break
        elif (find_truth == [16, 17]) or (find_truth == [17, 18]) or (find_truth == [17, 19]) or \
                (find_truth == [17, 20]) or (find_truth == [17, 21]) or (find_truth == [16, 22]) or \
                (find_truth == [22, 18]) or (find_truth == [22, 19]) or (find_truth == [22, 20]) or \
                (find_truth == [22, 21]):
            knowledge.wolfram_alpha(what_i_said)
            break
        else:
            decide(what_i_said)
            break