Skip to content

Commit 65b287a

Browse files
authored
Merge pull request #77 from ScrapeGraphAI/feat/add-time-range-searchscraper
feat: add time_range parameter to SearchScraper
2 parents 6ba97bb + 7db5a0c commit 65b287a

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

scrapegraph-py/scrapegraph_py/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from scrapegraph_py.models.searchscraper import (
6262
GetSearchScraperRequest,
6363
SearchScraperRequest,
64+
TimeRange,
6465
)
6566
from scrapegraph_py.models.sitemap import SitemapRequest, SitemapResponse
6667
from scrapegraph_py.models.smartscraper import (
@@ -783,6 +784,7 @@ async def searchscraper(
783784
extraction_mode: bool = True,
784785
stealth: bool = False,
785786
location_geo_code: Optional[str] = None,
787+
time_range: Optional[TimeRange] = None,
786788
return_toon: bool = False,
787789
):
788790
"""Send a searchscraper request
@@ -799,6 +801,7 @@ async def searchscraper(
799801
AI extraction costs 10 credits per page, markdown conversion costs 2 credits per page.
800802
stealth: Enable stealth mode to avoid bot detection
801803
location_geo_code: Optional geo code of the location to search in (e.g., "us")
804+
time_range: Optional time range filter for search results (e.g., TimeRange.PAST_WEEK)
802805
return_toon: If True, return response in TOON format (reduces token usage by 30-60%)
803806
"""
804807
logger.info("🔍 Starting searchscraper request")
@@ -811,6 +814,8 @@ async def searchscraper(
811814
logger.debug("🥷 Stealth mode enabled")
812815
if location_geo_code:
813816
logger.debug(f"🌍 Location geo code: {location_geo_code}")
817+
if time_range:
818+
logger.debug(f"📅 Time range: {time_range.value}")
814819
if return_toon:
815820
logger.debug("🎨 TOON format output enabled")
816821

@@ -822,6 +827,7 @@ async def searchscraper(
822827
extraction_mode=extraction_mode,
823828
stealth=stealth,
824829
location_geo_code=location_geo_code,
830+
time_range=time_range,
825831
)
826832
logger.debug("✅ Request validation passed")
827833

scrapegraph-py/scrapegraph_py/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from scrapegraph_py.models.searchscraper import (
5555
GetSearchScraperRequest,
5656
SearchScraperRequest,
57+
TimeRange,
5758
)
5859
from scrapegraph_py.models.sitemap import SitemapRequest, SitemapResponse
5960
from scrapegraph_py.models.smartscraper import (
@@ -790,9 +791,10 @@ def searchscraper(
790791
headers: Optional[dict[str, str]] = None,
791792
output_schema: Optional[BaseModel] = None,
792793
extraction_mode: bool = True,
793-
mock: bool=False,
794-
stealth: bool=False,
794+
mock: bool = False,
795+
stealth: bool = False,
795796
location_geo_code: Optional[str] = None,
797+
time_range: Optional[TimeRange] = None,
796798
return_toon: bool = False,
797799
):
798800
"""Send a searchscraper request
@@ -810,6 +812,7 @@ def searchscraper(
810812
mock: Enable mock mode for testing
811813
stealth: Enable stealth mode to avoid bot detection
812814
location_geo_code: Optional geo code of the location to search in (e.g., "us")
815+
time_range: Optional time range filter for search results (e.g., TimeRange.PAST_WEEK)
813816
return_toon: If True, return response in TOON format (reduces token usage by 30-60%)
814817
"""
815818
logger.info("🔍 Starting searchscraper request")
@@ -822,6 +825,8 @@ def searchscraper(
822825
logger.debug("🥷 Stealth mode enabled")
823826
if location_geo_code:
824827
logger.debug(f"🌍 Location geo code: {location_geo_code}")
828+
if time_range:
829+
logger.debug(f"📅 Time range: {time_range.value}")
825830
if return_toon:
826831
logger.debug("🎨 TOON format output enabled")
827832

@@ -834,6 +839,7 @@ def searchscraper(
834839
mock=mock,
835840
stealth=stealth,
836841
location_geo_code=location_geo_code,
842+
time_range=time_range,
837843
)
838844
logger.debug("✅ Request validation passed")
839845

scrapegraph-py/scrapegraph_py/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .feedback import FeedbackRequest
3030
from .scrape import GetScrapeRequest, ScrapeRequest
3131
from .markdownify import GetMarkdownifyRequest, MarkdownifyRequest
32-
from .searchscraper import GetSearchScraperRequest, SearchScraperRequest
32+
from .searchscraper import GetSearchScraperRequest, SearchScraperRequest, TimeRange
3333
from .sitemap import SitemapRequest, SitemapResponse
3434
from .smartscraper import GetSmartScraperRequest, SmartScraperRequest
3535
from .schema import GenerateSchemaRequest, GetSchemaStatusRequest, SchemaGenerationResponse
@@ -46,6 +46,7 @@
4646
"MarkdownifyRequest",
4747
"GetSearchScraperRequest",
4848
"SearchScraperRequest",
49+
"TimeRange",
4950
"SitemapRequest",
5051
"SitemapResponse",
5152
"GetSmartScraperRequest",

scrapegraph-py/scrapegraph_py/models/searchscraper.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,34 @@
1212
- Supports both AI extraction and markdown conversion modes
1313
"""
1414

15+
from enum import Enum
1516
from typing import Optional, Type
1617
from uuid import UUID
1718

1819
from pydantic import BaseModel, Field, model_validator
1920

2021

22+
class TimeRange(str, Enum):
23+
"""Time range filter for search results.
24+
25+
Controls how recent the search results should be. This is useful for
26+
finding recent news, updates, or time-sensitive information.
27+
28+
Values:
29+
PAST_HOUR: Results from the past hour
30+
PAST_24_HOURS: Results from the past 24 hours
31+
PAST_WEEK: Results from the past week
32+
PAST_MONTH: Results from the past month
33+
PAST_YEAR: Results from the past year
34+
"""
35+
36+
PAST_HOUR = "past_hour"
37+
PAST_24_HOURS = "past_24_hours"
38+
PAST_WEEK = "past_week"
39+
PAST_MONTH = "past_month"
40+
PAST_YEAR = "past_year"
41+
42+
2143
class SearchScraperRequest(BaseModel):
2244
"""
2345
Request model for the SearchScraper endpoint.
@@ -34,6 +56,7 @@ class SearchScraperRequest(BaseModel):
3456
mock: Whether to use mock mode for testing
3557
render_heavy_js: Whether to render heavy JavaScript
3658
location_geo_code: Optional geo code for location-based search (e.g., "us")
59+
time_range: Optional time range filter for search results
3760
3861
Example:
3962
>>> request = SearchScraperRequest(
@@ -74,6 +97,17 @@ class SearchScraperRequest(BaseModel):
7497
description="The geo code of the location to search in",
7598
example="us",
7699
)
100+
time_range: Optional[TimeRange] = Field(
101+
None,
102+
description="The date range to filter search results",
103+
examples=[
104+
TimeRange.PAST_HOUR,
105+
TimeRange.PAST_24_HOURS,
106+
TimeRange.PAST_WEEK,
107+
TimeRange.PAST_MONTH,
108+
TimeRange.PAST_YEAR,
109+
],
110+
)
77111

78112
@model_validator(mode="after")
79113
def validate_user_prompt(self) -> "SearchScraperRequest":

0 commit comments

Comments
 (0)