From 3dd37170143b0cd538f8aa002ee5b8f2b9333a2d Mon Sep 17 00:00:00 2001 From: leonghui Date: Sun, 3 Nov 2024 15:54:41 +0000 Subject: [PATCH] Handle empty response --- amazon_feed.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/amazon_feed.py b/amazon_feed.py index 40fd4aa..67a878d 100644 --- a/amazon_feed.py +++ b/amazon_feed.py @@ -226,7 +226,7 @@ def get_search_results(search_query): k: v for k, v in json_dict.items() if k.startswith("data-main-slot:search-result-") - } + } if json_dict else {} if search_query.strict: term_list = set([term.lower() for term in search_query.query_str.split()]) @@ -234,9 +234,7 @@ def get_search_results(search_query): f'"{search_query.query_str}" - strict mode enabled, title or asin must contain: {term_list}' ) - results_count = ( - json_dict.get("data-search-metadata").get("metadata").get("totalResultCount") - ) + results_count = len(results_dict) generated_items = []