def get(self): current_user = UserModel.find_by_username( get_jwt_identity()['username']) results = [] data = current_user.get_fav() for i in data: results.append([ RealtyModel.return_realty_by_id(i[0]), RealtyModel.return_realty_by_id(i[1]) ]) return {'favourites': results}, 200
def get(self): latitude = alt_parser.parse_args()['latitude'] longitude = alt_parser.parse_args()['longitude'] area = alt_parser.parse_args()['area'] data = RealtyModel.find_alt(latitude, longitude, area) return {'Matching results': data}, 200
def count_avg_sq(): districts = DistrictModel.query.all() flats = RealtyModel.query.all() for d in districts: sum = 0.0 count = 0 for f in flats: if f.type == 1: if d.id == f.dist: sum += f.price / f.area count += 1 if count > 0: d.avg_sq = sum / count RealtyModel.update_dist()
def parse_ao(): # with open('ao.json', 'r') as myfile: # data=myfile.read() # # obj = json.loads(data) # # for i in obj['features']: # new_ao = AoModel( # id=i['properties']['OKATO'], # name=i['properties']['NAME'], # type=i['geometry']['type'] # ) # # new_ao.save_to_db() # districts = DistrictModel.query.all() ao = AoModel.query.all() for a in ao: sumsq = 0.0 sumcoeff = 0 countsq = 0 countcoeff = 0 for d in districts: if a.id == d.okato_ao: if d.avg_sq: sumsq += d.avg_sq countsq += 1 if d.avg_coeff: sumcoeff += d.avg_coeff countcoeff += 1 if countsq != 0: a.avg_sq = sumsq / countsq if countcoeff != 0: a.avg_coeff = int(sumcoeff / countcoeff) RealtyModel.update_dist()
def count_avg_coeff(): districts = DistrictModel.query.all() flats = RealtyModel.query.all() flats_with_coeffs = TempModel.query.all() for fwc in flats_with_coeffs: for f in flats: if fwc.id == f.id: fwc.dist = f.dist RealtyModel.update_dist() for d in districts: coeff = 0 count = 0 for fwc in flats_with_coeffs: if d.id == fwc.dist: coeff += fwc.coeff count += 1 if count > 0: d.avg_coeff = int(coeff / count) RealtyModel.update_dist()
def check_point_is_in_polygon(): districts = DistrictModel.query.all() flats = RealtyModel.query.filter(RealtyModel.dist == None) res = 0 for d in districts: for f in flats: if d.type == "Polygon": if ray_tracing(f.longitude, f.latitude, np.array(d.coordinates)): print('here') res += 1 f.dist = d.id continue elif d.type == "MultiPolygon": for p in d.coordinates: if ray_tracing(f.longitude, f.latitude, np.array(p)): print('here') res += 1 f.dist = d.id continue RealtyModel.update_dist() print(RealtyModel.query.filter(RealtyModel.dist == None).count())
def get(self): res = RealtyModel.find_addresses() for key, value in res.items(): realty = TempModel.find_by_latlon(key[0], key[1]) if not realty: new_temp = TempModel(id=value[0].id, sell_url=value[0].url, rent_url=value[1].url, sell_price=value[0].price, rent_price=value[1].price, address=value[0].address, area=value[0].area, latitude=value[0].latitude, longitude=value[0].longitude, coeff=value[2]) new_temp.save_to_db() else: if realty.coeff > value[2]: realty.delete(realty.id) new_temp = TempModel(id=value[0].id, sell_url=value[0].url, rent_url=value[1].url, sell_price=value[0].price, rent_price=value[1].price, address=value[0].address, area=value[0].area, latitude=value[0].latitude, longitude=value[0].longitude, coeff=value[2]) new_temp.save_to_db() return {'message': 'Successfully updated db!'}, 200
def get(self): data = RealtyModel.return_all() return data, 200
def get(self): count = RealtyModel.count() return {'Total records': count}, 200
def get(self, id): return RealtyModel.return_realty_by_id(id)
def get(self): address = request.args.get('adr') results = RealtyModel.autocomplete(address) return jsonify(matching_results=results), 200
def update_db(price1, deal_id): count = 0 with urllib.request.urlopen( "https://rest-app.net/api-cian/[email protected]&token=3110c1024b85d2dcfc808b6d4aebc3ce&category_id=1&deal_id=" + str(deal_id) + "®ion_id=1&price1=" + str(price1)) as url: data = json.loads(url.read().decode()) for i in data['data']: if RealtyModel.find_by_id(i['Id']): continue try: new_realty = RealtyModel( id=i['Id'], url=i['url'], type=deal_id, price=float(i['price']), phone=i['phone'], metro=i['metro'], rooms_count=i['rooms_count'], floor_number=i['floor_number'], floors_count=i['floors_count'], images=i['images'], city=i['city'], address=i['address'], description=i['description'], area=float(i['area']), latitude=float(i['coords']['lat']), longitude=float(i['coords']['lng']), area_kitchen=i['area_kitchen'], time_publish=i['time_publish'], building_material_type=i['building_material_type'], status=1) new_realty.save_to_db() except KeyError as e: new_realty = RealtyModel(id=i['Id'], url=i['url'], type=deal_id, price=float(i['price']), phone=i['phone'], metro=i['metro'], rooms_count=i['rooms_count'], floor_number=i['floor_number'], floors_count=i['floors_count'], images=i['images'], city=i['city'], address=i['address'], description=i['description'], area=float(i['area']), latitude=float(i['coords']['lat']), longitude=float(i['coords']['lng']), area_kitchen=i['area_kitchen'], time_publish=i['time_publish'], building_material_type=None, status=1) new_realty.save_to_db() except Exception as er: print(e.__doc__) print(e.message) continue