def amazon_json(request, title, author=''): result = amazon.item_lookup(title, author) if result.imageurl == None: result.imageurl = 'http://www.librarygadget.com/images/noimage_available.png' #result.short_itemurl = shorten_url(result.itemurl) jsonresponse = json.dumps(result.__dict__) response = HttpResponse(jsonresponse) response['Content-Type'] = 'application/json; charset=utf-8' return response
def amazon_redirect(request): title = request.GET.get('title','') author = request.GET.get('author','') result = amazon.item_lookup(title, author) if result is None or result.itemurl is None: return HttpResponseRedirect(''.join( ["http://www.amazon.com/gp/search?ie=UTF8&tag=librgadg-20&index=blended&linkCode=ur2&camp=1789&creative=9325&", urllib.urlencode({'keywords': title})])) return HttpResponseRedirect(result.itemurl)
def amazon_image(request, size): title = request.GET.get('title','') author = request.GET.get('author','') result = amazon.item_lookup(title, author) if result is None or result.itemurl is None: return HttpResponseRedirect('/images/none.jpg') if size == 'small': return HttpResponseRedirect(result.small_image_url) if size == 'large': return HttpResponseRedirect(result.large_image_url) return HttpResponseRedirect(result.medium_image_url)
def noop_test_no_image(self): itemresult = amazon.item_lookup('Judas and the Gospel of Jesus : have we missed the truth about Christianity?', 'Wright, N. T. (Nicholas Thomas)') self.assertEquals('amazon', itemresult.source) self.assert_not_empty(itemresult)
def test_item_loookup(self): itemresult = amazon.item_lookup('Love in the Ruins', 'Percy, Walker') self.assertEquals('amazon', itemresult.source) self.assert_not_empty(itemresult)