Skip to content

Commit

Permalink
Update visualize.py
Browse files Browse the repository at this point in the history
Add error handling when visualizing via id or name
  • Loading branch information
Crinibus committed Dec 12, 2021
1 parent 6f84c66 commit a8a8483
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scraper/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@


def show_id(id: str) -> None:
print(f"Visualizing product with id: {id}")

product_data = get_product_with_id(id)

if not product_data:
print(f"Couldn't find product with id: {id}")
return

print(f"Visualizing product with id: {id}")

product_name = product_data["name"]
product_info = product_data["info"]

Expand Down Expand Up @@ -62,10 +66,14 @@ def show_category(category: str) -> None:


def show_name(name: str) -> None:
print(f"Visualizing product with name: {name.lower()}")

product_info = get_product_with_name(name)

if not product_info:
print(f"Couldn't find product with name: {name.lower()}")
return

print(f"Visualizing product with name: {name.lower()}")

fig = go.Figure()

is_up_to_date = False
Expand Down Expand Up @@ -194,12 +202,14 @@ def get_product_with_id(id: str) -> dict:
"category": product_info["category"],
"info": website_info,
}
return None


def get_product_with_name(name: str) -> dict:
for product_info in format_data():
if product_info["name"].lower() == name.lower():
return product_info
return None


def get_all_products() -> Generator[dict, None, None]:
Expand Down

0 comments on commit a8a8483

Please sign in to comment.