refactor the semaphore when dumping listings

This commit is contained in:
Viktor Barzin 2025-06-06 20:08:38 +00:00
parent b7a2ea75aa
commit 29213f3d26
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
2 changed files with 34 additions and 29 deletions

View file

@ -121,7 +121,6 @@ async def listing_query(
property_type: list[PropertyType] = [],
page_size: int = 25,
furnish_types: list[FurnishType] = [],
semaphore: asyncio.Semaphore | None = None,
) -> dict[str, Any]:
params: dict[str, str] = {
"locationIdentifier": location_id,
@ -164,16 +163,12 @@ async def listing_query(
"Connection": "keep-alive",
}
if semaphore is None:
semaphore = asyncio.Semaphore(1)
async with semaphore:
async with aiohttp.ClientSession(trust_env=True) as session:
async with session.get(
"https://api.rightmove.co.uk/api/property-listing",
params=params,
headers=headers,
) as response:
if response.status != 200:
raise Exception(f"Failed due to: {await response.text()}")
return await response.json()
async with aiohttp.ClientSession(trust_env=True) as session:
async with session.get(
"https://api.rightmove.co.uk/api/property-listing",
params=params,
headers=headers,
) as response:
if response.status != 200:
raise Exception(f"Failed due to: {await response.text()}")
return await response.json()