use aiohttp to fetch details concurrently

This commit is contained in:
Viktor Barzin 2025-05-17 22:34:27 +00:00
parent 61b8c82592
commit 01ac24b4b7
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
5 changed files with 602 additions and 21 deletions

View file

@ -1,6 +1,7 @@
# from diskcache import Cache
import enum
from typing import List
import aiohttp
import requests
import urllib3
@ -36,14 +37,14 @@ async def detail_query(detail_id: int):
"appVersion": "3.70.0",
}
url = f"https://api.rightmove.co.uk/api/property/{detail_id}"
response = requests.get(url, params=params, headers=headers, verify=False)
if response.status_code != 200:
raise Exception(
f"""id: {detail_id}. Status Code: {response.status_code}."""
f"""Failed due to: {response.text}"""
)
return response.json()
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params, headers=headers) as response:
if response.status != 200:
raise Exception(
f"""id: {detail_id}. Status Code: {response.status}."""
f"""Failed due to: {await response.text()}"""
)
return await response.json()
async def listing_query(