| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import db
- import geo_util
- import config
- def load_properties(require_active=True):
- with db.connect() as conn:
- rows = conn.select('select id, lat, lon, size, price, bedrooms, ber from properties where price<%i and property_type != "Site"' % config.MAX_PRICE)
- res = {}
- for property_id, lat, lon, size, price, bedrooms, ber in rows:
- if not price or not size or not lat or not lon:
- continue
- if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES):
- continue
- price = price/1000
- res[property_id] = {
- 'loc': (lat, lon),
- 'size': size,
- 'price': price,
- 'bedrooms': bedrooms,
- 'price_history': [],
- 'ber': ber,
- }
- rows = conn.select('select property_id, price from search_results order by time asc')
- for pid, price in rows:
- if pid not in res:
- continue
- if price.isdigit():
- price = int(price)
- res[pid]['price'] = price/1000
-
- res[pid]['price_history'].append(price)
- if require_active:
- res = {k: v for k, v in res.items() if v['price_history'] and v['price_history'][-1] != 'GONE'}
- return res
|