Skip to content

Commit

Permalink
Merge pull request #254 from Crinibus/fix/add-message-when-no-product…
Browse files Browse the repository at this point in the history
…s-found

Print message if no products are found when visualizing or listing products
  • Loading branch information
Crinibus authored Oct 13, 2024
2 parents 7f454a3 + 8a4d007 commit e28101d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scraper/print_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def print_all_products() -> None:
print("\n----- SHOWING ALL PRODUCTS -----")
categories = db.get_all_unique_categories()

if not categories:
print("No products")
return

for category in categories:
print(category.upper())

Expand Down
16 changes: 16 additions & 0 deletions scraper/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def visualize_data(

master_products = get_master_products()

if not master_products:
print("No products saved")
return

if compare:
compare_products(master_products, ids, names, categories, only_up_to_date, show_all)
return
Expand All @@ -33,20 +37,26 @@ def visualize_data(
status_of_master_product = get_status_of_master_product(master_product)
title = f"Price(s) of {product_name} - {category} - {status_of_master_product}"
show_products(master_product.products, title)
else:
print("No products found with category/categories")

if ids:
for product in get_products_with_ids(master_products, ids, only_up_to_date):
status_of_product = get_status_of_product(product)
product_name = product.product_name.upper()
title = f"Price(s) of {product_name} - {status_of_product}"
show_product(product, title)
else:
print("No products found with id(s)")

if names:
for master_product in get_master_products_with_names(master_products, names, only_up_to_date):
product_name = master_product.product_name.upper()
status_of_master_product = get_status_of_master_product(master_product)
title = f"Price(s) of {product_name} - {status_of_master_product}"
show_products(master_product.products, title)
else:
print("No products found with name(s)")


def compare_products(
Expand All @@ -70,6 +80,10 @@ def compare_products(
if show_all:
products_to_compare = get_products_from_master_products(master_products)

if not products_to_compare:
print("No products found to compare")
return

product_ids = [product.id for product in products_to_compare]
product_ids_string = ", ".join(product_ids)
title_ = product_ids_string[:100] + " ..." if len(product_ids_string) > 100 else product_ids_string
Expand All @@ -85,6 +99,8 @@ def show_master_products(master_products: tuple[MasterProduct], only_up_to_date:
show_products(
master_product.products, f"Price(s) of {master_product.product_name.upper()} - {status_of_master_product}"
)
else:
print("No products found")


def show_product(product: ProductInfo, title: str) -> None:
Expand Down

0 comments on commit e28101d

Please sign in to comment.