Example #1
0
def key(h, key):
    try:
        if key == 'cover url':
            return getOrCacheImage(h[key])
        else:
            return h[key]
    except:
        return u''
def key(h, key):
	try:
		if key == 'cover url':
			return getOrCacheImage(h[key])
		else:
			return h[key]
	except:
		return u''
Example #3
0
def get_cover_image(imdb_url):
    print "Getting cover for image %s" % (imdb_url)
    if imdb_url == '' or imdb_url == None:
        return ''
    else:
        try:
            return getOrCacheImage(imdb_url)
        except:
            return ''
def get_cover_image(imdb_url):
	print "Getting cover for image %s" % (imdb_url)
	if imdb_url == '' or imdb_url == None:
		return ''
	else:
		try:
		  return getOrCacheImage(imdb_url)
		except:
		  return ''
Example #5
0
def search_json(request):
    if not (request.GET.has_key('q') or request.GET.has_key('type')):
        # error handling
        print "Error: request does not have keys q and type: %s" % (request.keys())
        return HttpResponse("", mimetype='text/plain; encoding=UTF-8')
    else:
        query = request.GET['q']
        qtype = request.GET['type']
        limit = (int (request.GET['limit']) if request.GET.has_key('limit') else 5)
        string_list = query.split(" ")
        
        if qtype == "actor":
            results = Actor_Model.objects.all()
        elif qtype == "writer":
            results = Writer_Model.objects.all()
        elif qtype == "director":
            results = Director_Model.objects.all()
        elif qtype == "character":
            results = Character_Model.objects.all()
        elif qtype == "genre":
            results = Genre_Model.objects.all()
        elif qtype in ["movie-original-title", "movie-aka-title"]:
            results = Movie_Model.objects.all()
            
        for word in string_list:
            if qtype in ["movie-original-title", "movie-aka-title"]:
                results = results.filter(original_title__icontains = word)
                result_strings = [ {'name': r.original_title, 'img': r.thumbnail_url} for r in results[:limit]]
            elif qtype in ["actor", "writer", "director"]:
                results = results.filter(full_name__icontains = word)
                result_strings = [ {'name': r.full_name, 'img': r.thumbnail_url} for r in results[:limit]]
            elif qtype == "character":
                results = results.filter(character_name__icontains = word)
                # , 'img': r.thumbnail_url to character...
                result_strings = [ {'name': r.character_name, 'img': ""} for r in results[:limit]]
            elif qtype == "genre":
                results = results.filter(genre_name__icontains = word)
                result_strings = [ {'name': r.genre_name, 'img': ""} for r in results[:limit]]
            
        data = ""
        for r in result_strings:
            data = data + r['name'];
            if qtype in ["movie-original-title", "movie-aka-title", "actor", "writer", "director", "character"]:
                image = getOrCacheImage(r['img'])
                if not (image == None or image == ""): 
                    data = data + "&" + image
            data = data + "\n"
            
#        data = simplejson.dumps({'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
#        data = serializers.serialize('json', {'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
        print data
#        return HttpResponse(serializers.serialize('json', {'error': 'none', 'data': result_strings}), mimetype='application/json')
#        return HttpResponse(serializers.serialize('json', result_strings), mimetype='application/json')
#        return HttpResponse(json, mimetype='application/json')
        return HttpResponse(content = data, mimetype='text/plain; encoding=UTF-8')
Example #6
0
def search_json(request):
    if not (request.GET.has_key('q') or request.GET.has_key('type')):
        # error handling
        print "Error: request does not have keys q and type: %s" % (
            request.keys())
        return HttpResponse("", mimetype='text/plain; encoding=UTF-8')
    else:
        query = request.GET['q']
        qtype = request.GET['type']
        limit = (int(request.GET['limit'])
                 if request.GET.has_key('limit') else 5)

        if qtype == "person":
            results = Person.objects.all()
        elif qtype == "character":
            results = Character.objects.all()
        elif qtype == "genre":
            results = Genre.objects.all()
        else:
            results = Movie.objects.all()

        for word in query.split(" "):
            if qtype == "movie":
                results = results.filter(title__icontains=word)
            else:
                results = results.filter(name__icontains=word)

        if qtype == "movie":
            result_strings = [{
                'name': r.title,
                'img': r.image_url
            } for r in results[:limit]]
        else:
            result_strings = [{
                'name': r.name,
                'img': r.image_url
            } for r in results[:limit]]

        data = ""
        for r in result_strings:
            data = data + r['name']
            if qtype == "movie" or qtype == "person":
                image = getOrCacheImage(r['img'])
                if not (image == None or image == ""):
                    data = data + "&" + image
            data = data + "\n"

#		data = simplejson.dumps({'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
#		data = serializers.serialize('json', {'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
        print data
        #		return HttpResponse(serializers.serialize('json', {'error': 'none', 'data': result_strings}), mimetype='application/json')
        #		return HttpResponse(serializers.serialize('json', result_strings), mimetype='application/json')
        #		return HttpResponse(json, mimetype='application/json')
        return HttpResponse(content=data,
                            mimetype='text/plain; encoding=UTF-8')
Example #7
0
def search_json(request):
	if not (request.GET.has_key('q') or request.GET.has_key('type')):
		# error handling
		print "Error: request does not have keys q and type: %s" % (request.keys())
		return HttpResponse("", mimetype='text/plain; encoding=UTF-8')
	else:
		query = request.GET['q']
		qtype = request.GET['type']
		limit = (int (request.GET['limit']) if request.GET.has_key('limit') else 5)
		
		
		if qtype == "person":
			results = Person.objects.all()
		elif qtype == "character":
			results = Character.objects.all()
		elif qtype == "genre":
			results = Genre.objects.all()
		else:
			results = Movie.objects.all()
			
		for word in query.split(" "):
			if qtype == "movie":
				results = results.filter(title__icontains = word)
			else:
				results = results.filter(name__icontains = word)
				
		if qtype == "movie":
			result_strings = [ {'name': r.title, 'img': r.image_url} for r in results[:limit]]
		else:
			result_strings = [ {'name': r.name, 'img': r.image_url} for r in results[:limit]]
			
		data = ""
		for r in result_strings:
			data = data + r['name'];
			if qtype == "movie" or qtype == "person":
				image = getOrCacheImage(r['img'])
				if not (image == None or image == ""): 
					data = data + "&" + image
			data = data + "\n"
			
#		data = simplejson.dumps({'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
#		data = serializers.serialize('json', {'message': {'type': 'debug', 'msg': 'no error'}, 'data': result_strings})
		print data
#		return HttpResponse(serializers.serialize('json', {'error': 'none', 'data': result_strings}), mimetype='application/json')
#		return HttpResponse(serializers.serialize('json', result_strings), mimetype='application/json')
#		return HttpResponse(json, mimetype='application/json')
		return HttpResponse(content = data, mimetype='text/plain; encoding=UTF-8')