Put more logging into Goodreads handling to try to debug why shelf loading not working in some cases.

pull/1/head
Raymond Yee 2011-11-10 07:36:17 -08:00
parent a959d00508
commit df8d1d9506
2 changed files with 11 additions and 3 deletions

View File

@ -216,6 +216,9 @@ def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id
Load a specified Goodreads shelf (by default: all the books from the Goodreads account associated with user) Load a specified Goodreads shelf (by default: all the books from the Goodreads account associated with user)
""" """
logger.info('Entering load_goodreads_shelf_into_wishlist. user: %s, shelf_name: %s, goodreads_user_id: %s, max_books: %s',
user, shelf_name, goodreads_user_id, max_books)
gc = GoodreadsClient(key=settings.GOODREADS_API_KEY, secret=settings.GOODREADS_API_SECRET, user=user) gc = GoodreadsClient(key=settings.GOODREADS_API_KEY, secret=settings.GOODREADS_API_SECRET, user=user)
if goodreads_user_id is None: if goodreads_user_id is None:
@ -224,6 +227,8 @@ def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id
else: else:
raise Exception("No Goodreads user_id is associated with user.") raise Exception("No Goodreads user_id is associated with user.")
logger.info('computed goodreads_user_id: %s ', goodreads_user_id)
for (i, review) in enumerate(islice(gc.review_list(goodreads_user_id,shelf=shelf_name),max_books)): for (i, review) in enumerate(islice(gc.review_list(goodreads_user_id,shelf=shelf_name),max_books)):
isbn = review["book"]["isbn10"] if review["book"]["isbn10"] is not None else review["book"]["isbn13"] isbn = review["book"]["isbn10"] if review["book"]["isbn10"] is not None else review["book"]["isbn13"]
logger.info("%d %s %s %s ", i, review["book"]["title"], isbn, review["book"]["small_image_url"]) logger.info("%d %s %s %s ", i, review["book"]["title"], isbn, review["book"]["small_image_url"])
@ -234,5 +239,6 @@ def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id
user.wishlist.works.add(edition.work) user.wishlist.works.add(edition.work)
logger.info("Work with isbn %s added to wishlist.", isbn) logger.info("Work with isbn %s added to wishlist.", isbn)
except Exception, e: except Exception, e:
logger.info ("error adding ISBN %s: %s", isbn, e) logger.info ("Exception adding ISBN %s: %s", isbn, e)
logger.info('Leaving load_goodreads_shelf_into_wishlist. Length of wishlist for user %s is %s', user, len(user.wishlist.works.all()))

View File

@ -327,6 +327,7 @@ def goodreads_flush_assoc(request):
profile.goodreads_auth_token = None profile.goodreads_auth_token = None
profile.goodreads_auth_secret = None profile.goodreads_auth_secret = None
profile.save() profile.save()
logger.info('Goodreads association flushed for user %s', user)
return HttpResponseRedirect(reverse('goodreads_display')) return HttpResponseRedirect(reverse('goodreads_display'))
@require_POST @require_POST
@ -345,7 +346,7 @@ def goodreads_load_shelf(request):
return HttpResponse("Shelf loading placed on task queue.") return HttpResponse("Shelf loading placed on task queue.")
except Exception,e: except Exception,e:
return HttpResponse("Error in loading shelf: %s " % (e)) return HttpResponse("Error in loading shelf: %s " % (e))
logger.info("Error in loading shelf: %s ", e) logger.info("Error in loading shelf for user %s: %s ", user, e)
@require_POST @require_POST
@login_required @login_required
@ -353,10 +354,11 @@ def goodreads_load_shelf(request):
def clear_wishlist(request): def clear_wishlist(request):
try: try:
request.user.wishlist.works.clear() request.user.wishlist.works.clear()
logger.info("Wishlist for user %s cleared", request.user)
return HttpResponse('wishlist cleared') return HttpResponse('wishlist cleared')
except Exception, e: except Exception, e:
return HttpResponse("Error in clearing wishlist: %s " % (e)) return HttpResponse("Error in clearing wishlist: %s " % (e))
logger.info("Error in clearing wishlist: %s ", e) logger.info("Error in clearing wishlist for user %s: %s ", request.user, e)
def celery_test(request): def celery_test(request):