def test_approx_distance(self): #point, origin): #crouch end to screen on the green crouch = geo.LatLng(lat=51.579585, lng=-0.123729) cinema = geo.LatLng(lat=51.536812, lng=-0.103633) dist = geo.approx_distance(crouch, cinema) actual = 3.06 assert (actual * 0.9) < dist < (actual * 1.1)
def load_one_item(owner): item_test_data = items_data_list[0] it = models.Item.query( models.Item.place_name == item_test_data[ITEM_NAME]).get() if it: return it else: new_it = models.Item() cat = models.Category.get_by_id(item_test_data[ITEM_CATEGORY]) if not cat: cat = models.Category(id=item_test_data[ITEM_CATEGORY]).put() new_it.category = cat new_it.place_name = item_test_data[ITEM_NAME] home = geo.LatLng(lat=51.57, lng=-0.13) lat_long = geo.geoCodeAddress(item_test_data[1], home) new_it.lat = lat_long['lat'] new_it.lng = lat_long['lng'] new_it.address = item_test_data[ITEM_ADDRESS] new_it.owner = owner.key.integer_id() # new_it.descr = "blah" new_it.geo_hash = geohash.encode(new_it.lat, new_it.lng) img = models.DBImage() detail = geo.getPlaceDetailFromGoogle(new_it) img.remoteURL = detail['photo'] img.put() new_it.photo = img new_it.telephone = detail['telephone'] new_it.put() return new_it
def get_item_list(cls, request, include_maps_data, user_id, exclude_user_id=None): """ get the list of item around a place @param request: @param include_maps_data: bool: include data from google maps? @param user_id: @return: list of JSON points """ around = geo.LatLng(lat=float(request.get("lat")), lng=float(request.get("lng"))) try: my_locn = geo.LatLng(lat=float(request.get("myLat")), lng=float(request.get("myLng"))) except Exception, E: # logging.exception("get_item_list " + str(E)) my_locn = around
def get(self): logging.debug('getAddresses_ajax') address = self.request.get("addr") lat = float(self.request.get("lat")) lng = float(self.request.get("lng")) names = self.request.get("place_name").split(" ") near_me = self.request.get("near_me") if near_me == u'0': # near the address url = ("https://maps.googleapis.com/maps/api/geocode/json?address=%s" "&sensor=false&key=%s&bounds=%f,%f|%f,%f") % \ (urllib2.quote(address), config['google_api_key'], lat-0.3, lng-0.3, lat+0.3, lng+0.3) response = urllib2.urlopen(url) jsonResult = response.read() addressResult = json.loads(jsonResult) if addressResult['status'] == "OK": lat = addressResult['results'][0]['geometry']['location']['lat'] lng = addressResult['results'][0]['geometry']['location']['lng'] results = PlacesDB.map_and_db_search( self.request, -1, '', True, lat, lng, geo.LatLng(lat=lat, lng=lng), self.request.get("place_name").lower(), self.user_id) if results: results['search'] = {'lat': lat,'lng':lng} # check_for_dirty_data(self, results) json.dump(results, self.response.out, default=json_serial) else: # logging.info("get_google_db_places near [%f,%f]: %s" % # (lat, lng, "none found")) logging.debug("getAddresses_ajax - none found ") self.error(401)
def get(self): try: logging.debug('getStrangerPlaces') lat = float(self.request.get("lat")) lng = float(self.request.get("lng")) place_names = [] results = geo.findDbPlacesNearLoc(geo.LatLng(lat=lat, lng=lng), place_names=place_names) if results: results['search'] = {'lat': lat, 'lng': lng} # check_for_dirty_data(self, results) json.dump(results, self.response.out, default=views.json_serial) else: # logging.info("get_google_db_places near [%f,%f]: %s" % # (lat, lng, "none found")) logging.debug("getStrangerPlaces - none found ") self.error(401) except Exception: logging_ext.error("getStrangerPlaces", True)
'place_id': '0', 'geometry': { 'location': { 'lat': 54.0 + random(), 'lng': -(1.0 + random()) } } }] } else: logging_ext.error('get_google_db_places Exception in Load', exc_info=True) return None if addressResult['status'] == "OK": try: origin = geo.LatLng(lat=lat, lng=lng) for r in addressResult['results']: if "formatted_address" in r: address = r['formatted_address'] else: address = r['vicinity'] post_code = r['postal_code'].split( ' ')[0] if 'postal_code' in r else '' detail = { 'place_name': r['name'], 'address': address, 'post_code': post_code, 'place_id': r['place_id'], "lat": r['geometry']['location']['lat'], "lng": r['geometry']['location']['lng'], 'website': '',
def load_data(wipe=False, section=None, Max=None): if not settings.running_on_test_server(): return "Forbidden" result_strings = [] if geo.geoCodeAddress("1 Crouch Hill, London"): # if we can geocode, we will - no fake fakeGeoCoder = None else: # if we cant geocode, use the fake one fakeGeoCoder = fakeGeoCode if section == "addresses": return add_addresses_to_db() else: if wipe: # wipe_table("User") wipe_table("Category") wipe_table("Item") wipe_table("Vote") print "wiped" if not section or section == 'user': for idx, usr in enumerate(Users): if Max: if idx >= Max: break user_name = usr[0] this_user = User.get_by_auth_id(user_name) if not this_user: email = usr[1] name = usr[2] last_name = usr[3] password = usr[4] unique_properties = ['email_address'] this_user = User.create_user(user_name, unique_properties, email_address=email, name=name, password_raw=password, last_name=last_name, verified=False) if not this_user[0]: # user_data is a tuple result_strings.append("ERROR - User: "******"User: "******"User exists: " + usr[0]) a_sample_user = User.get_by_auth_id( Users[0][0]) # used for the owner of the records print "users ok" if not section or section == "category": for idx, cat in enumerate(Categories): if Max: if idx >= Max: break if models.Category.get_by_id(cat): result_strings.append("Category exists: " + cat) else: new_cat = models.Category(id=cat) new_cat.title = cat new_cat.put() result_strings.append("Created: " + cat) print "category ok" if not section or section == "item": home = geo.LatLng(lat=51.57, lng=-0.13) for idx, item in enumerate(items_data_list): if Max: if idx >= Max: break it = models.Item.query(models.Item.place_name == item[0]).get() if it: result_strings.append("Item exists: " + item[0]) it.category = models.Category.get_by_id(item[2]).key it.save() else: new_it = models.Item() new_it.category = models.Category.get_by_id(item[2]).key new_it.place_name = item[0] lat_long = fakeGeoCode( ) if fakeGeoCoder else geo.geoCodeAddress(item[1]) new_it.lat = lat_long['lat'] new_it.lng = lat_long['lng'] new_it.address = item[1] new_it.owner = a_sample_user.key.id() # new_it.descr = "blah" new_it.geo_hash = geohash.encode(new_it.lat, new_it.lng) img = models.DBImage() detail = geo.getPlaceDetailFromGoogle(new_it) remoteURL = detail['photo'] if remoteURL: main_url = remoteURL % 250 data = urllib2.urlopen(main_url) img.picture = db.Blob(data.read()) img.remoteURL = None thumb_url = remoteURL % 65 thumb_data = urllib2.urlopen(thumb_url) img.thumb = db.Blob(thumb_data.read()) img.put() new_it.photo = img.key new_it.telephone = detail['telephone'] new_it.put() result_strings.append('Item: ' + item[0]) print "items" # votes items = models.Item.query() i = 0 for idx, vote_item in enumerate(items): if Max: if idx >= Max: break vote = models.Vote() vote_score = randint(0, 5) if vote_score == 0: vote.stars = 0 vote.untried = True else: vote.stars = vote_score vote.untried = False vote.comment = "blah v" + str(i) vote.voter = a_sample_user.key.integer_id() vote.item = vote_item.key vote.cuisine = vote_item.category vote.put() i += 1 result_strings.append("Votes") print "votes" if not section or section == 'friends': for idx, pair in enumerate(FriendsList): if Max: if idx >= Max: break left = User.get_by_auth_id(pair[0]) right = User.get_by_auth_id(pair[1]) left_prof = left.profile() models.Friends.addFriends(left.get_id(), right.get_id()) result_strings.append("Friends %s - %s" % (pair[0], pair[1])) print "friends" return result_strings