ruff format

This commit is contained in:
Kadir Tugan 2023-11-18 12:30:04 +02:00
parent 65fc4cdda4
commit d49b11e28b
3 changed files with 39 additions and 36 deletions

View file

@ -31,5 +31,5 @@ class RightmoveListing(Base):
) )
if __name__ == '__main__': if __name__ == "__main__":
Base.metadata.create_all(engine) Base.metadata.create_all(engine)

View file

@ -6,55 +6,61 @@ import requests
from rec.db import RightmoveListing from rec.db import RightmoveListing
import urllib3 import urllib3
urllib3.disable_warnings() urllib3.disable_warnings()
cache = Cache(r'_cache') cache = Cache(r"_cache")
headers = { headers = {
'Host': 'api.rightmove.co.uk', "Host": "api.rightmove.co.uk",
# 'Accept-Encoding': 'gzip, deflate, br', # 'Accept-Encoding': 'gzip, deflate, br',
'User-Agent': 'okhttp/4.10.0', "User-Agent": "okhttp/4.10.0",
'Connection': 'close', "Connection": "close",
} }
@cache.memoize() @cache.memoize()
def listing_query(page: int, min_bedrooms: int, max_bedrooms: int): def listing_query(page: int, min_bedrooms: int, max_bedrooms: int):
print("Executing") print("Executing")
params = { params = {
'locationIdentifier': 'POSTCODE^4228216', "locationIdentifier": "POSTCODE^4228216",
'channel': 'BUY', "channel": "BUY",
'page': str(page), "page": str(page),
'numberOfPropertiesPerPage': '25', "numberOfPropertiesPerPage": "25",
'radius': '5.0', "radius": "5.0",
'sortBy': 'distance', "sortBy": "distance",
'includeUnavailableProperties': 'false', "includeUnavailableProperties": "false",
'propertyTypes': 'flat', "propertyTypes": "flat",
'dontShow': 'sharedOwnership,retirement', "dontShow": "sharedOwnership,retirement",
'minPrice': '150000', "minPrice": "150000",
'maxPrice': '500000', "maxPrice": "500000",
'minBedrooms': str(min_bedrooms), "minBedrooms": str(min_bedrooms),
'maxBedrooms': str(max_bedrooms), "maxBedrooms": str(max_bedrooms),
'apiApplication': 'ANDROID', "apiApplication": "ANDROID",
'appVersion': '3.70.0', "appVersion": "3.70.0",
} }
response = requests.get('https://api.rightmove.co.uk/api/property-listing', params=params, headers=headers, response = requests.get(
verify=False) "https://api.rightmove.co.uk/api/property-listing",
params=params,
headers=headers,
verify=False,
)
if response.status_code != 200: if response.status_code != 200:
raise Exception("Failed due to: ", response.text) raise Exception("Failed due to: ", response.text)
return response.json() return response.json()
if __name__ == '__main__': if __name__ == "__main__":
response = listing_query(1, 2, 2) response = listing_query(1, 2, 2)
resp = response resp = response
for d in resp['properties']: for d in resp["properties"]:
rl = RightmoveListing( rl = RightmoveListing(
id=d['identifier'], id=d["identifier"],
listing_json=d, listing_json=d,
price=d['price'], price=d["price"],
updated_timestamp = d['updateDate'], updated_timestamp=d["updateDate"],
) )
rl.save() rl.save()

View file

@ -1,11 +1,8 @@
def parse_listing_json_entry(d): def parse_listing_json_entry(d):
id = d['identifier'] id = d["identifier"]
# address = d['address'] # address = d['address']
propertyType = d['propertyType'] propertyType = d["propertyType"]
price = d['price'] price = d["price"]
latitude = d['latitude'] latitude = d["latitude"]
longitude = d['longitude'] longitude = d["longitude"]
updated_date = d['updateDate'] updated_date = d["updateDate"]