Esempio n. 1
0
def checker(userName, person_name, oldMovie, newMovie_name):
    try:
        # Finds the person in IMDB, gets the id code for person
        pers = ia.search_person(person_name.title())
        p = ia.get_person(pers[0].personID)
        pName = p['name']

        checkMovie = ''  # Variable to hold the movie id of the movie that will be checked

        if (oldMovie == ''):  # If no movie was being talked about previously
            print(
                f'IMDBot: Before I can check if {pName} was in {newMovie_name}, I need to confirm the movie.'
            )
            checkMovie = f.searchForMovie(
                userName,
                newMovie_name)  # Search for the new movie being talked about
            if (
                    checkMovie == ''
            ):  # checkMovie will only return blank if the user said to stop searching
                return 'User cancelled'
        else:
            oldMovie_name = oldMovie['title']
            if oldMovie_name != newMovie_name:  # If the old movie and new movie names don't match
                print(
                    f'IMDBot: Before I can check if {pName} was in {newMovie_name}, I need to confirm the movie.'
                )
                while True:
                    print(
                        f'IMDBot: We were talking about {oldMovie_name}. Want me to search for {newMovie_name}?'
                    )
                    searchCheck = input(userName + ': ')
                    sCheckFirst = searchCheck[:1].lower(
                    )  # Save first letter (might only need y or n)
                    sCheckArr = sy.getArray(
                        searchCheck,
                        [])  # Turn user input into array for synonym checking
                    if (
                            sCheckFirst == 'y'
                            or sy.findSyns(sCheckArr, 'yes') == 0
                    ):  # If the user does want to search for the new movie name
                        checkMovie = f.searchForMovie(userName, newMovie_name)
                        if (
                                checkMovie == ''
                        ):  # checkMovie will only return blank if the user said to stop searching
                            return 'User Cancelled'
                        break
                    elif (
                            sCheckFirst == 'n'
                            or sy.findSyns(sCheckArr, 'no') == 0
                    ):  # If the user does not want to search for the new movie name
                        print(
                            'IMDBot: Ok. I\'ll check if {pName} was in {oldMovie_name}.'
                        )
                        checkMovie = oldMovie
                        break
                    else:
                        print(f'IMDBot: I\'m sorry, I don\'t understand. ')
            else:  # if the old movie name and new movie name match
                checkMovie = oldMovie  # check using the old movie because we already have the movie ID

        checkMovie_name = checkMovie['title']
        if (p in checkMovie):
            print(f'IMDBot: Yes, {pName} was in {checkMovie_name}!')
            return True
        else:
            print(f'IMDBot: No, {pName} was not in {checkMovie_name}.')
            return False
    except:
        print(
            "IMDBot: Woops! Something went wrong. What else can I help you with?"
        )
        return 'Error Found'
Esempio n. 2
0
 def test_searchForMovie(self):  # FROM FILM.py
     with patch('builtins.input', return_value = 'y') as mock_input:
         r = f.searchForMovie(name,self.movieName)
         mock_input.assert_called_once()
         self.assertEqual(r, self.movie)