Skip to content

Commit

Permalink
Merge pull request #167 from Crinibus/print-websites-and-id-when-sear…
Browse files Browse the repository at this point in the history
…ching-with-name

Print websites and id when searching with name
  • Loading branch information
Crinibus authored Sep 16, 2022
2 parents 9e6197f + e50dd9e commit 4b19293
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions scraper/search_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
def search(queries: List[str]):
print("Searching...")

records_data = Filemanager.get_record_data()

for query in queries:
search_functions = [search_product_name, search_categories]
searching_for_names = [
Expand All @@ -13,7 +15,7 @@ def search(queries: List[str]):
]

for search_function, searching_for_name in zip(search_functions, searching_for_names):
results = search_function(query)
results = search_function(query, records_data)

if not results:
print(f"\nFound nothing for search term '{query}' when searching for {searching_for_name[0]}")
Expand All @@ -25,21 +27,24 @@ def search(queries: List[str]):
print()


def search_product_name(product_name_search: str):
records_data = Filemanager.get_record_data()

matched_product_names = []
def search_product_name(product_name_search: str, records_data: dict) -> List[str]:
matched_products = []

for category_info in records_data.values():
for product_name in category_info.keys():
for category_dict in records_data.values():
for product_name, product_dict in category_dict.items():
if product_name_search.lower() in product_name.lower():
matched_product_names.append(product_name)
return matched_product_names

product_websites = []
for website_name, website_dict in product_dict.items():
id = website_dict["info"]["id"]
product_websites.append(f" - {website_name.capitalize()} - {id}")

product_websites_string = "\n".join(product_websites)
matched_products.append(f"{product_name}\n{product_websites_string}")
return matched_products

def search_categories(category_search: str):
records_data = Filemanager.get_record_data()

def search_categories(category_search: str, records_data: dict) -> List[str]:
matched_categories = []

for category_name in records_data.keys():
Expand Down

0 comments on commit 4b19293

Please sign in to comment.