refactor the semaphore when dumping listings
This commit is contained in:
parent
b7a2ea75aa
commit
29213f3d26
2 changed files with 34 additions and 29 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue