def get(self): user = users.get_current_user() if user: mapimage = MapImage.all().filter('user ='******'error')
def get(self): user = users.get_current_user() if user: mapimage = MapImage.all().filter('user ='******'domain': environ['HTTP_HOST'], 'mapimage_url': 'map/%s.png' % mapimage.key(), 'public_url': 'public/%s.html' % mapimage.key(), } os_path = os.path.dirname(__file__) self.response.out.write(template.render(os.path.join(os_path, 'templates/static_map.html'), template_data)) else: self.response.out.write("")
def get(self): user = users.get_current_user() if user: mapimage = MapImage.all().filter('user ='******'domain': environ['HTTP_HOST'], 'static_url': mapimage.static_url, 'mapimage_url': 'map/%s.png' % mapimage.key(), 'public_url': 'public/%s.html' % mapimage.key(), 'timestamp': str(time.time()) } os_path = os.path.dirname(__file__) self.response.out.write( template.render( os.path.join(os_path, 'templates/static_map.html'), template_data)) else: self.response.out.write("")
def update_map_file(): # really there should be a flag in the user object to indicate the map needs updating, but for that to be reliable that needs to put with each new checkin, so these need to have the user as the parent so the transaction works, and that's just a nightmare. mapimages = MapImage.all().order('last_updated').fetch(10) for mapimage in mapimages: if not mapimage.update_count: mapimage.update_count = 0 mapimage.put() userinfo = UserInfo.all().filter('user = '******'s no userinfo mapimage.put() logging.warning("No userinfo found for mapimage with user %s" % mapimage.user) continue try: if userinfo.last_updated > mapimage.last_updated or mapimage.update_count == 0: google_data = { 'key': constants.get_google_maps_apikey(), 'zoom': mapimage.zoom, 'center': str(mapimage.centerlat) + "," + str(mapimage.centerlng), 'size': str(mapimage.width) + "x" + str(mapimage.height), 'sensor':'false', 'format':'png', } img = update_map_image(mapimage.user, mapimage.zoom, mapimage.width, mapimage.height, mapimage.northlat, mapimage.westlng) mapimage.img = db.Blob(img) mapimage.last_updated = datetime.now() mapimage.static_url = "http://maps.google.com/maps/api/staticmap?" + urllib.urlencode(google_data) mapimage.update_count += 1 mapimage.put() logging.info("Updated user map for %s" % mapimage.user) return # only update one map else: # so that we don't get stuck on the same maps forever mapimage.last_updated = datetime.now() mapimage.put() logging.debug("Did not need to update map for %s" % mapimage.user) except DeadlineExceededError, err: logging.error("Ran out of time before updating a map! %s" % err) mapimage.last_updated = datetime.now() # put it at the end of the queue anyway, in case we always fail on this map for some reason mapimage.put()
assert northwest.count(',') == 1, "%d ,'s" % northwest.count(',') northlat, westlng = northwest.split(',') northlat, westlng = float(northlat), float(westlng) except AssertionError, err: logging.error(err.args[0]) return try: google_data = { 'key': constants.google_maps_apikey, 'zoom': zoom, 'center': centerpoint, 'size': widthxheight, 'sensor':'false', 'format':'png', } mapimage = MapImage.all().filter('user =', user).get() if not mapimage: mapimage = MapImage() mapimage.user = user def reset_map_image(mapimage_param, centerlat_param, centerlng_param, northlat_param, westlng_param, zoom_param, height_param, width_param, google_data_param): mapimage_param.tiles_remaining = len(range(0, width_param, 256)) * len(range(0, height_param, 256)) mapimage_param.centerlat = centerlat_param mapimage_param.centerlng = centerlng_param mapimage_param.northlat = northlat_param mapimage_param.westlng = westlng_param mapimage_param.zoom = zoom_param mapimage_param.height = height_param mapimage_param.width = width_param mapimage_param.static_url = "http://maps.google.com/maps/api/staticmap?" + urllib.urlencode(google_data_param) mapimage_param.img = None mapimage_param.put()
# mapimages = MapImage.all().fetch(500) # db.delete(mapimages) # while(UserVenue.all().count() > 0): # uservenues = UserVenue.all().fetch(500) # db.delete(uservenues) # while(AuthToken.all().count() > 0): # authtokens = AuthToken.all().fetch(500) # db.delete(authtokens) # while(UserInfo.all().count() > 0): # userinfos = UserInfo.all().fetch(500) # db.delete(userinfos) elif rest == 'user': user = users.get_current_user() if user: while (MapImage.all().filter('user ='******'user ='******'user = '******'user = '******'user ='******'user ='******'mapimage': user = users.get_current_user() if user: while (MapImage.all().filter('user ='******'user =', user).fetch(500) db.delete(mapimages)
# mapimages = MapImage.all().fetch(500) # db.delete(mapimages) # while(UserVenue.all().count() > 0): # uservenues = UserVenue.all().fetch(500) # db.delete(uservenues) # while(AuthToken.all().count() > 0): # authtokens = AuthToken.all().fetch(500) # db.delete(authtokens) # while(UserInfo.all().count() > 0): # userinfos = UserInfo.all().fetch(500) # db.delete(userinfos) elif rest == 'user': user = users.get_current_user() if user: while(MapImage.all().filter('user ='******'user ='******'user = '******'user = '******'user ='******'user ='******'mapimage': user = users.get_current_user() if user: while(MapImage.all().filter('user ='******'user =', user).fetch(500) db.delete(mapimages)
assert centerpoint.count(',') == 1, "%d ,'s" % centerpoint.count(',') centerlat, centerlng = centerpoint.split(',') assert northwest.count(',') == 1, "%d ,'s" % northwest.count(',') northlat, westlng = northwest.split(',') except AssertionError, err: logging.error(err.args[0]) return google_data = { 'key': constants.get_google_maps_apikey(), 'zoom': zoom, 'center': centerpoint, 'size': widthxheight, 'sensor':'false', 'format':'png', } mapimage = MapImage.all().filter('user =', user).get() if not mapimage: mapimage = MapImage() mapimage.user = user mapimage.centerlat = float(centerlat) mapimage.centerlng = float(centerlng) mapimage.northlat = float(northlat) mapimage.westlng = float(westlng) mapimage.zoom = int(zoom) mapimage.height = int(height) mapimage.width = int(width) img = update_map_image(user, google_data, int(width), int(height), float(northlat), float(westlng)) mapimage.img = db.Blob(img) mapimage.last_updated = datetime.now() mapimage.put()