From 84ce636cfd687de865fa16b1be104ebc7a9f0ecf Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Sun, 8 Jul 2012 15:05:20 -0400 Subject: [PATCH] Debug Amazon --- views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/views.py b/views.py index f5ccecd..615ebe9 100644 --- a/views.py +++ b/views.py @@ -18,7 +18,7 @@ def amazon_search(request): products = [] if request.GET.get('q'): amazon = AmazonAPI('AKIAJJRRQPTSPKB7GYOA', 'DIYz2g5vPjcWE4/YI7wEuUVAskwJxs2llFvGyI1a', 'snipt-20') - products = amazon.search_n(5, Keywords=request.GET.get('q'), SearchIndex='Books') + products = amazon.search_n(5, Keywords=request.GET.get('q'), SearchIndex='All') result = [] for product in products: @@ -47,12 +47,17 @@ def amazon_image(request): img_src = 'http://ecx.images-amazon.com/images/I/{}'.format(img_filename) img_loc = os.path.join(settings.STATIC_ROOT, 'images', 'amazon', img_filename) + if settings.DEBUG: + root = '/static/images/amazon/' + else: + root = 'https://snipt.net/static/images/amazon/' + try: open(img_loc) - return HttpResponseRedirect('https://snipt.net/static/images/amazon/' + img_filename) + return HttpResponseRedirect(root + img_filename) except IOError: urllib.urlretrieve(img_src, img_loc) - return HttpResponseRedirect('https://snipt.net/static/images/amazon/' + img_filename) + return HttpResponseRedirect(root + img_filename) else: return HttpResponseBadRequest()