updating poetry
This commit is contained in:
parent
200caadabd
commit
65fc4cdda4
7 changed files with 261 additions and 50 deletions
0
rec/__init__.py
Normal file
0
rec/__init__.py
Normal file
35
rec/db.py
Normal file
35
rec/db.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import Column, Integer, String, JSON, FLOAT
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
engine = create_engine("sqlite:///sqlite.db", echo=True)
|
||||
session = Session(engine)
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class RightmoveListing(Base):
|
||||
__tablename__ = "rightmove"
|
||||
id = Column(Integer, primary_key=True)
|
||||
price = Column(FLOAT)
|
||||
listing_json = Column(JSON, nullable=True)
|
||||
detail_json = Column(JSON, nullable=True)
|
||||
updated_timestamp = Column(Integer, nullable=True)
|
||||
distance_to_office_minutes = Column(FLOAT, nullable=True)
|
||||
|
||||
def save(self):
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
def __repr__(self):
|
||||
return "<User(name='%s', fullname='%s', nickname='%s')>" % (
|
||||
self.name,
|
||||
self.fullname,
|
||||
self.nickname,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Base.metadata.create_all(engine)
|
||||
60
rec/query.py
Normal file
60
rec/query.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import pickle
|
||||
|
||||
import cachetools
|
||||
from diskcache import Cache
|
||||
import requests
|
||||
from rec.db import RightmoveListing
|
||||
|
||||
import urllib3
|
||||
urllib3.disable_warnings()
|
||||
|
||||
cache = Cache(r'_cache')
|
||||
|
||||
|
||||
headers = {
|
||||
'Host': 'api.rightmove.co.uk',
|
||||
# 'Accept-Encoding': 'gzip, deflate, br',
|
||||
'User-Agent': 'okhttp/4.10.0',
|
||||
'Connection': 'close',
|
||||
}
|
||||
|
||||
@cache.memoize()
|
||||
def listing_query(page: int, min_bedrooms: int, max_bedrooms: int):
|
||||
print("Executing")
|
||||
params = {
|
||||
'locationIdentifier': 'POSTCODE^4228216',
|
||||
'channel': 'BUY',
|
||||
'page': str(page),
|
||||
'numberOfPropertiesPerPage': '25',
|
||||
'radius': '5.0',
|
||||
'sortBy': 'distance',
|
||||
'includeUnavailableProperties': 'false',
|
||||
'propertyTypes': 'flat',
|
||||
'dontShow': 'sharedOwnership,retirement',
|
||||
'minPrice': '150000',
|
||||
'maxPrice': '500000',
|
||||
'minBedrooms': str(min_bedrooms),
|
||||
'maxBedrooms': str(max_bedrooms),
|
||||
'apiApplication': 'ANDROID',
|
||||
'appVersion': '3.70.0',
|
||||
}
|
||||
|
||||
response = requests.get('https://api.rightmove.co.uk/api/property-listing', params=params, headers=headers,
|
||||
verify=False)
|
||||
if response.status_code != 200:
|
||||
raise Exception("Failed due to: ", response.text)
|
||||
|
||||
return response.json()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
response = listing_query(1, 2, 2)
|
||||
resp = response
|
||||
for d in resp['properties']:
|
||||
rl = RightmoveListing(
|
||||
id=d['identifier'],
|
||||
listing_json=d,
|
||||
price=d['price'],
|
||||
updated_timestamp = d['updateDate'],
|
||||
)
|
||||
rl.save()
|
||||
11
rec/rightmove_parser.py
Normal file
11
rec/rightmove_parser.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
def parse_listing_json_entry(d):
|
||||
id = d['identifier']
|
||||
# address = d['address']
|
||||
propertyType = d['propertyType']
|
||||
price = d['price']
|
||||
latitude = d['latitude']
|
||||
longitude = d['longitude']
|
||||
updated_date = d['updateDate']
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue