示例#1
0
	def processPagingIMDB(self, pagenumber, dmoutput):
		start = (pagenumber-1) * self.pagesize
		end   = pagenumber * self.pagesize
		for x in range(start,end):
			movie = self.list[x]
			item = ListItem()
			item.add_entity("name", movie["title"])
			item.add_entity("year", movie["year"])
			dmoutput.add_listitem(item)
示例#2
0
	def processPaging(self, pagenumber, dmoutput):
		
		dmoutput.setPageNumber(pagenumber)
		dmoutput.setTotalPages(int(math.ceil(len(self.list)/self.pagesize)))
		
		start = (pagenumber-1) * self.pagesize
		end   = pagenumber * self.pagesize
		counter = 1
		for x in range(start,end):
			if x == len(self.list):
				break
			movie = self.list[x]
			item = ListItem()
			item.add_entity("listNumber", (pagenumber-1)*self.pagesize+counter)
			item.add_entity("name", movie.get_title())
			item.add_entity("year", movie.get_year())
			item.add_entity("score", movie.get_score())
			dmoutput.add_listitem(item)
			counter += 1
示例#3
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")
示例#4
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")