Exemplo n.º 1
0
	def processTriviaConfirm(self, entities):
		
		name = ""
		
		if not entities.has_entity("movieTitle"):
			return DmOutput("notunderstood")
		
		movie = entities.find_entity("movieTitle")
		
		if entities.has_entity("director"):
			name = entities.find_entity("director") 
			director = self.imdb.get_director(movie)
			print "DIRECTOR: " + director
			
			if director == "":
				return DmOutput("notavailable", movie)
			else:
				director = "'"+director+"'"
				name2 = self.imdb.encodeName(name)
				print "CMP: " + name2 + "=?" + director
				result = director == name2
					
		elif entities.has_entity("actor"):
			name = entities.find_entity("actor") 
			result = self.imdb.is_person_in_movie(name, movie) 
		elif entities.has_entity("person"):
			name = entities.find_entity("person")
			result = self.imdb.is_person_in_movie(name, movie) 
		
		if name != "":
			if result:
				s = DmOutput("INTHERE", False, movie)
				item = ListItem()
				item.add_entity("name", name)
				s.add_listitem(item)
				return s
			else:
				s = DmOutput("NOTTHERE", False, movie)
				item = ListItem()
				item.add_entity("name", name)
				s.add_listitem(item)
				return s
		
		return DmOutput("notunderstood")
Exemplo n.º 2
0
	def processTrivia(self, entities):
		if len(entities.get_entitylist()) == 1 or not entities.has_entity("type") :
			return DmOutput("notunderstood")
		
		#type, movieTitle, person, range
		
		if entities.has_entity("range"):
			queryrange =  entities.find_entity("range")
		
			# top 250 , bottom 100 movies with paging	
			if queryrange in ("top", "bottom"):
				self.status = DialogManager.PAGING
				self.page = 1
				self.pagesize = 10

			if queryrange == "top":
				dmoutput = DmOutput("topratingmovies", True)
				self.list =  self.imdb.get_top250()

			if queryrange == "bottom":
				dmoutput = DmOutput("worstmovies", True)
				self.list =  self.imdb.get_bottom100()
				
			self.page = 1
			self.processPagingIMDB(self.page, dmoutput)

			return dmoutput
		
		querytype = entities.find_entity("type")
		querytype = querytype.lower().strip()
		if querytype == "plot":
			title = self.getMovieTitle(entities)
			if title == "":
				return DmOutput("insufficientparameter")
				
			plot = self.imdb.get_plot(title)
			if plot == "":
				s = DmOutput("notavailable", False, title)
				return s	
			else:
				s = DmOutput("plot", False, title)
				item = ListItem()
				item.add_entity("plot", plot)
				s.add_listitem(item)
				return s
				
		if querytype == "cast" or querytype == "actor":
			if entities.has_entity("movieTitle"):
				castlist = self.imdb.get_castlist(entities.find_entity("movieTitle"))
				if len(castlist) == 0:
					return DmOutput("notavailable", False, entities.find_entity("movieTitle"))
				else:
					s = DmOutput("cast", False, entities.find_entity("movieTitle"))
					for person in castlist:
						item = ListItem()	
						item.add_entity("name", person)
						s.add_listitem(item)
						
					#self.list = castlist
					#self.page = 1
					#self.processPaging(self.page, s)
					#self.status = DialogManager.PAGING
					
					return s
		
		if querytype == "movietitle":
			self.list = self.imdb.get_movielist(entities)
			needpaging = False
			self.page = 1
			self.pagesize = 10
			
			if len(self.list) == 0:
				return DmOutput("notavailable")
			
			if len(self.list) > 10:
				self.status = DialogManager.PAGING
				needpaging = True

			dmoutput = DmOutput("movielist", needpaging)
				
			self.page = 1
			self.processPaging(self.page, dmoutput)
			
			return dmoutput
		
		if querytype == "director":
			title = self.getMovieTitle(entities)
			if title == "":
				return DmOutput("insufficientparameter")
						
			director = self.imdb.get_director(title)

			if director == "":
				return DmOutput("notavailable", title)
			else:
				s = DmOutput("director", False, title)
				item = ListItem()	
				item.add_entity("name", director)
				s.add_listitem(item)						
				return s
		
		return DmOutput("notunderstood")