properties.py 743 B

123456789101112131415161718192021222324252627
  1. import db
  2. import geo_util
  3. import config
  4. import ranking
  5. def load_properties():
  6. with db.connect() as conn:
  7. rows = conn.select('select id, lat, lon, size, price, bedrooms from properties where price<450000')
  8. res = {}
  9. for property_id, lat, lon, size, price, bedrooms in rows:
  10. if not price or not size or not lat or not lon:
  11. continue
  12. if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES):
  13. continue
  14. price = price/1000
  15. res[property_id] = {
  16. 'loc': (lat, lon),
  17. 'size': size,
  18. 'price': price,
  19. 'bedrooms': bedrooms,
  20. }
  21. return res