Skip to content

Commit

Permalink
Merge pull request #243 from Crinibus/add-format-methods
Browse files Browse the repository at this point in the history
Add static methods 'db_products_to_product_infos' and 'db_product_to_product_info' to Format class
  • Loading branch information
Crinibus authored Jan 30, 2024
2 parents 611fff2 + 3172881 commit 9716565
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scraper/format.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import scraper.database as db
from scraper.models.product import ProductInfo
from scraper.scrape import Scraper
from scraper.domains import get_website_name


class Format:
Expand All @@ -25,3 +27,23 @@ def scraper_to_db_product(product: Scraper, is_active: bool) -> db.Product:
short_url=product.website_handler.get_short_url(),
is_active=is_active,
)

@staticmethod
def db_products_to_product_infos(products: list[db.Product]) -> list[ProductInfo]:
product_infos = []
for product in products:
product_info = Format.db_product_to_product_info(product)
product_infos.append(product_info)
return product_infos

@staticmethod
def db_product_to_product_info(product: db.Product) -> ProductInfo:
return ProductInfo(
product_name=product.name,
category=product.category,
url=product.short_url,
id=product.product_code,
currency=None,
website=get_website_name(product.short_url, keep_subdomain=False),
datapoints=None,
)

0 comments on commit 9716565

Please sign in to comment.