fix types and format
This commit is contained in:
parent
91d3237516
commit
b873eaf203
8 changed files with 117 additions and 172 deletions
|
|
@ -1,11 +1,11 @@
|
|||
# from diskcache import Cache
|
||||
import enum
|
||||
from typing import List
|
||||
from typing import Any, List
|
||||
import aiohttp
|
||||
import requests
|
||||
import urllib3
|
||||
|
||||
urllib3.disable_warnings()
|
||||
urllib3.disable_warnings() # type: ignore
|
||||
|
||||
|
||||
class ListingType(enum.StrEnum):
|
||||
|
|
@ -38,12 +38,12 @@ async def detail_query(detail_id: int):
|
|||
}
|
||||
url = f"https://api.rightmove.co.uk/api/property/{detail_id}"
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, params=params, headers=headers) as response:
|
||||
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()}"""
|
||||
)
|
||||
f"""Failed due to: {await response.text()}""")
|
||||
return await response.json()
|
||||
|
||||
|
||||
|
|
@ -57,11 +57,11 @@ async def listing_query(
|
|||
max_price: int,
|
||||
location_id: str = "STATION^5168", # kings cross station
|
||||
mustNewHome: bool = False,
|
||||
max_days_since_added: int = None,
|
||||
max_days_since_added: int = 30,
|
||||
property_type: List["PropertyType"] = [],
|
||||
page_size=25,
|
||||
) -> dict:
|
||||
params = {
|
||||
page_size: int = 25,
|
||||
) -> dict[str, Any]:
|
||||
params: dict[str, str] = {
|
||||
"locationIdentifier": location_id,
|
||||
"channel": channel.upper(),
|
||||
"page": str(page),
|
||||
|
|
@ -77,14 +77,14 @@ async def listing_query(
|
|||
"appVersion": "4.28.0",
|
||||
}
|
||||
if channel is ListingType.BUY:
|
||||
params["dontShow"] = "sharedOwnership,retirement",
|
||||
params["dontShow"] = "sharedOwnership,retirement"
|
||||
if len(property_type) > 0:
|
||||
params["propertyTypes"] = ",".join(property_type)
|
||||
if max_days_since_added is not None and max_days_since_added not in [
|
||||
1, 3, 7, 14
|
||||
1, 3, 7, 14
|
||||
]:
|
||||
raise Exception("Invalid max days. Can only be", [1, 3, 7, 14])
|
||||
params["maxDaysSinceAdded"] = max_days_since_added
|
||||
params["maxDaysSinceAdded"] = str(max_days_since_added)
|
||||
|
||||
if mustNewHome:
|
||||
params["mustHave"] = "newHome"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue