From 870e7ef9e90e18eb34ae114567c43bc06417b5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Fri, 22 Nov 2024 13:41:29 +0100 Subject: [PATCH] Google Search: remove the max_requests widget (#87) --- tests/test_serp.py | 3 +-- zyte_spider_templates/spiders/serp.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_serp.py b/tests/test_serp.py index 4de4e29..9ca50c3 100644 --- a/tests/test_serp.py +++ b/tests/test_serp.py @@ -292,7 +292,7 @@ def test_metadata(): "widget": "textarea", }, "max_requests": { - "anyOf": [{"type": "integer"}, {"type": "null"}], + "anyOf": [{"type": "integer", "minimum": 1}, {"type": "null"}], "default": 100, "description": ( "The maximum number of Zyte API requests allowed for the crawl.\n" @@ -302,7 +302,6 @@ def test_metadata(): "and do not increase the request count in Scrapy Cloud." ), "title": "Max Requests", - "widget": "request-limit", }, "max_pages": { "default": 1, diff --git a/zyte_spider_templates/spiders/serp.py b/zyte_spider_templates/spiders/serp.py index 3106682..6490a81 100644 --- a/zyte_spider_templates/spiders/serp.py +++ b/zyte_spider_templates/spiders/serp.py @@ -19,7 +19,6 @@ from .._geolocations import GEOLOCATION_OPTIONS_WITH_CODE, Geolocation from ..documentation import document_enum -from ..params import MaxRequestsParam from ._google_domains import GoogleDomain from ._google_gl import GOOGLE_GL_OPTIONS_WITH_CODE, GoogleGl from ._google_hl import GOOGLE_HL_OPTIONS_WITH_CODE, GoogleHl @@ -144,6 +143,21 @@ class SerpMaxPagesParam(BaseModel): ) +# MaxRequestsParam without the widget. +class SerpMaxRequestsParam(BaseModel): + max_requests: Optional[int] = Field( + description=( + "The maximum number of Zyte API requests allowed for the crawl.\n" + "\n" + "Requests with error responses that cannot be retried or exceed " + "their retry limit also count here, but they incur in no costs " + "and do not increase the request count in Scrapy Cloud." + ), + default=100, + ge=1, + ) + + class SerpResultsPerPageParam(BaseModel): results_per_page: Optional[int] = Field( title="Results Per Page", @@ -226,7 +240,7 @@ class GoogleSearchSpiderParams( SerpItemTypeParam, SerpResultsPerPageParam, SerpMaxPagesParam, - MaxRequestsParam, + SerpMaxRequestsParam, SearchQueriesParam, GoogleDomainParam, BaseModel,