Skip to content

Commit

Permalink
Apply naming suggested by Kevin
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Feb 15, 2024
1 parent 289bfd8 commit e1c0b89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tests/test_ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ def test_crawl():
assert request.callback == spider.parse_navigation


def test_crawl_strategy_none():
def test_crawl_strategy_direct_product():
crawler = get_crawler()
spider = EcommerceSpider.from_crawler(
crawler,
url="https://example.com",
crawl_strategy="none",
crawl_strategy="direct_product",
)
start_requests = list(spider.start_requests())
assert len(start_requests) == 1
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_metadata():
"title": "Crawl strategy",
"description": "Determines how the start URL and follow-up URLs are crawled.",
"type": "string",
"enum": ["full", "navigation", "pagination_only", "none"],
"enum": ["full", "navigation", "pagination_only", "direct_product"],
"enumMeta": {
"full": {
"description": "Follow most links within the domain of URL in an attempt to discover and extract as many products as possible.",
Expand All @@ -389,12 +389,12 @@ def test_metadata():
),
"title": "Pagination Only",
},
"none": {
"direct_product": {
"description": (
"Treat input URLs as direct links to product detail pages, and "
"extract a product from each."
),
"title": "None",
"title": "Direct URLs to Product",
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions zyte_spider_templates/spiders/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EcommerceCrawlStrategy(str, Enum):
ignored. Use this when some subCategory links are misidentified by
ML-extraction."""

none: str = "none"
direct_product: str = "direct_product"
"""Treat input URLs as direct links to product detail pages, and
extract a product from each."""

Expand All @@ -59,8 +59,8 @@ class EcommerceSpiderParams(BaseSpiderParams):
"Use this when some subCategory links are misidentified by ML-extraction."
),
},
EcommerceCrawlStrategy.none: {
"title": "None",
EcommerceCrawlStrategy.direct_product: {
"title": "Direct URLs to Product",
"description": (
"Treat input URLs as direct links to product detail pages, and "
"extract a product from each."
Expand Down Expand Up @@ -126,7 +126,7 @@ def from_crawler(cls, crawler: Crawler, *args, **kwargs) -> scrapy.Spider:
def start_requests(self) -> Iterable[Request]:
callback = (
self.parse_product
if self.args.crawl_strategy == EcommerceCrawlStrategy.none
if self.args.crawl_strategy == EcommerceCrawlStrategy.direct_product
else self.parse_navigation
)
page_params = {}
Expand Down

0 comments on commit e1c0b89

Please sign in to comment.