class Bot(object): def __init__(self): self.movielens = MovieLens() self.recommendation = Recommendation(self.movielens) self.movie_picker = MoviePicker(self.movielens) self.users = {} def respond_to(self, sender, message): user = self.register_user(sender) user.process_message(message) if user.should_make_recommendation(): user.reset_remaining_questions_number() return self.recommendation.make_recommendation(user) else: intro = u"" # If the user speak for the first time, display a welcome message if not user.has_been_asked_a_question(): intro = u"Hello ! Je vais vous poser des questions puis vous faire une recommandation.\n" message = self.ask_question(user) return intro + message # Register a user if it does not exist and return it def register_user(self, sender): if sender not in self.users.keys(): self.users[sender] = User(sender) return self.users[sender] def ask_question(self, user): movie = self.movie_picker.pick_a_movie() user.set_pending_question(movie) return u"Sur une échelle de 0 à 5, à quel point avez-vous aimé : " + movie.title + u" ?"
class Bot(object): def __init__(self): self.movielens = MovieLens() self.recommendation = Recommendation(self.movielens) self.movie_picker = MoviePicker(self.movielens) self.picked_movies = [] self.users = {} def respond_to(self, sender, message): user = self.register_user(sender) user.process_message(message) if user.should_make_recommendation(): user.reset_remaining_questions_number() return self.recommendation.make_recommendation(user) else: intro = u"" # If the user speak for the first time, display a welcome message if not user.has_been_asked_a_question(): intro = u"Salut ma poule ! Je vais te poser quelques questions puis te faire une petite recommandation de film. \n" message = self.ask_question(user) return intro + message # Register a user if it does not exist and return it def register_user(self, sender): if sender not in self.users.keys(): self.users[sender] = User(sender) return self.users[sender] def ask_question(self, user): movie = self.movie_picker.pick_a_movie() #We check if we have already picked this movie while (movie in self.picked_movies): movie = self.movie_picker.pick_a_movie() self.picked_movies.append(movie) user.set_pending_question(movie) return u"As-tu kiffé : " + movie.title + "? (NOTE SUR 5). \n Si tu connais pas écrit \"pass\""