Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print websites and id when searching with name #167

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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