def google_location(loc): time.sleep(0.5) gg = gcd.google(loc + ', London UK') while gg.status != 'ZERO_RESULTS': if gg.status == 'OK': pc = gg.postal if len(pc) > 4: ac = pc[:pc.find(' ')] else: ac = pc return { 'address': gg.address, 'lng': gg.lng, 'lat': gg.lat, 'hood': gg.neighborhood, 'my_hood': areacode_to_hood(ac), 'the_geom': WKTElement('POINT(' + str(gg.lat) + ' ' + str(gg.lng) + ')', srid=4326), 'post_code': pc, 'area_code': ac } if gg.status is 'OVER_QUERY_LIMIT': return None
def postcode_geo_from_db(pc, loc): pc_geo_data = db.session.query(PostCodeGeoData).filter( PostCodeGeoData.postcode == pc).first() if pc_geo_data: ac = extract_areacode_from_pc(pc_geo_data.postcode) return { 'address': loc, 'lng': pc_geo_data.longitude, 'lat': pc_geo_data.latitude, 'post_code': pc_geo_data.postcode, 'area_code': ac, 'my_hood': areacode_to_hood(ac), 'hood': pc_geo_data.ward, 'the_geom': pc_geo_data.the_geom }