@@ -54,7 +54,7 @@ class HackerNewsSource(SourceSpec):
5454 """Source spec for HackerNews API."""
5555
5656 tag : str | None = None
57- max_results : int = 100
57+ max_results : int = 200
5858
5959
6060@source_connector (
@@ -77,24 +77,16 @@ async def create(spec: HackerNewsSource) -> "HackerNewsConnector":
7777 """Create a HackerNews connector from the spec."""
7878 return HackerNewsConnector (spec , aiohttp .ClientSession ())
7979
80- async def _ensure_session (self ) -> aiohttp .ClientSession :
81- """Ensure we have an active HTTP session."""
82- if self ._session is None or self ._session .closed :
83- self ._session = aiohttp .ClientSession ()
84- return self ._session
85-
8680 async def list (
8781 self ,
8882 ) -> AsyncIterator [PartialSourceRow [_HackerNewsThreadKey , _HackerNewsThread ]]:
8983 """List HackerNews threads using the search API."""
90- session = await self ._ensure_session ()
91-
9284 # Use HackerNews search API
9385 search_url = "https://hn.algolia.com/api/v1/search_by_date"
9486 params : dict [str , Any ] = {"hitsPerPage" : self ._spec .max_results }
9587 if self ._spec .tag :
9688 params ["tags" ] = self ._spec .tag
97- async with session .get (search_url , params = params ) as response :
89+ async with self . _session .get (search_url , params = params ) as response :
9890 response .raise_for_status ()
9991 data = await response .json ()
10092 for hit in data .get ("hits" , []):
@@ -114,12 +106,10 @@ async def get_value(
114106 self , key : _HackerNewsThreadKey
115107 ) -> PartialSourceRowData [_HackerNewsThread ]:
116108 """Get a specific HackerNews thread by ID using the items API."""
117- session = await self ._ensure_session ()
118-
119109 # Use HackerNews items API to get full thread with comments
120110 item_url = f"https://hn.algolia.com/api/v1/items/{ key .thread_id } "
121111
122- async with session .get (item_url ) as response :
112+ async with self . _session .get (item_url ) as response :
123113 response .raise_for_status ()
124114 data = await response .json ()
125115
@@ -183,7 +173,7 @@ def hackernews_flow(
183173
184174 # Add the custom source to the flow
185175 data_scope ["threads" ] = flow_builder .add_source (
186- HackerNewsSource (tag = "story" , max_results = 500 ),
176+ HackerNewsSource (tag = "story" , max_results = 200 ),
187177 refresh_interval = timedelta (minutes = 1 ),
188178 )
189179
0 commit comments