def resource_db_from_upload(album_db): try: uploaded_file = flask.request.files['file'] except: return None headers = uploaded_file.headers['Content-Type'] blob_info_key = werkzeug.parse_options_header(headers)[1]['blob-key'] blob_info = blobstore.BlobInfo.get(blob_info_key) image_url = None if blob_info.content_type.startswith('image'): try: image_url = images.get_serving_url(blob_info.key()) except: pass resource_db = model.Resource( album_key=album_db.key, user_key=auth.current_user_key(), blob_key=blob_info.key(), name=blob_info.filename, content_type=blob_info.content_type, size=blob_info.size, image_url=image_url, bucket_name=config.CONFIG_DB.bucket_name or None, ) resource_db.put() return resource_db
def json_to_resources(raw_resources): resources = [] for raw_resource in raw_resources: resource = model.Resource(raw_resource.get("name"), model.ResourceType[raw_resource.get("type")]) resources.append(resource) return resources
def resource_db_from_upload(): try: uploaded_file = flask.request.files['file'] except: return None bucket_name, origin_dir, object_name = extract_cloud_storage_meta_data( uploaded_file) headers = uploaded_file.headers['Content-Type'] blob_info_key = werkzeug.parse_options_header(headers)[1]['blob-key'] blob_info = blobstore.BlobInfo.get(blob_info_key) gcs_object_path = "{}/{}/{}".format(bucket_name, origin_dir, object_name) image_url = None public_url = None if blob_info.content_type.startswith('image'): try: image_url = images.get_serving_url(blob_info.key(), secure_url=True) except: pass else: response = storage.objects().patch( bucket=bucket_name, object="{}/{}".format(origin_dir, object_name), body={ 'acl': [{ "entity": "project-owners-825037505474", "role": "OWNER" }, { "entity": "project-editors-825037505474", "role": "OWNER" }, { "entity": "project-viewers-825037505474", "role": "READER" }, { "entity": "allUsers", "role": "READER" }] }).execute() public_url = "https://storage.googleapis.com/{}?content_type={}".format( gcs_object_path, blob_info.content_type) resource_db = model.Resource( user_key=auth.current_user_key(), blob_key=blob_info.key(), name=blob_info.filename, content_type=blob_info.content_type, size=blob_info.size, image_url=image_url, public_url=public_url, bucket_name=get_bucket_and_path_name() or None, gcs_object_path=gcs_object_path, ) resource_db.put() return resource_db
def resource_db_from_upload(): try: uploaded_file = flask.request.files['file'] except: return None headers = uploaded_file.headers['Content-Type'] blob_info_key = werkzeug.parse_options_header(headers)[1]['blob-key'] blob_info = blobstore.BlobInfo.get(blob_info_key) logging.info('Photo Info') logging.info('blob_info.size: {}'.format(blob_info.size)) logging.info('blob_info.md5_hash: {}'.format(blob_info.md5_hash)) logging.info('blob_info.creation: {}'.format(blob_info.creation)) image_obj = images.Image(blob_key=blob_info.key()) # image_obj.im_feeling_lucky() image_obj.resize(width=100) output = image_obj.execute_transforms(parse_source_metadata=True) logging.info('image_obj.width: {}'.format(image_obj.width)) logging.info('image_obj.height: {}'.format(image_obj.height)) metadata = image_obj.get_original_metadata() logging.info('metadata: {}'.format(metadata)) logging.info('type(metadata): {}'.format(type(metadata))) image_url = None if blob_info.content_type.startswith('image'): try: image_url = images.get_serving_url(blob_info.key(), secure_url=True) except: pass taken_at = metadata.get('DateTimeOriginal') if taken_at: taken_at = datetime.datetime.fromtimestamp(float(taken_at)) resource_db = model.Resource( user_key=auth.current_user_key(), blob_key=blob_info.key(), name=blob_info.filename, content_type=blob_info.content_type, size=blob_info.size, image_url=image_url, metadata=metadata, taken_at=taken_at, camera_make=metadata.get('Make'), camera_model=metadata.get('Model'), md5_hash=blob_info.md5_hash, width=metadata.get('ImageWidth') or image_obj.width, height=metadata.get('ImageLength') or image_obj.height, bucket_name=config.CONFIG_DB.bucket_name or None, ) resource_db.put() return resource_db
def generateResource(self, tile): """ returns a random resource (or none) depending on tile's tileId """ if tile.tileId == model.GRASSLAND: # grassland probability distribution: # None: 97% # Wheat: 2.75% # Mountain: 0.25% randomNum = random() if randomNum > 1 - 0.0275: return model.Resource(tile, model.WHEAT) elif randomNum > 1 - 0.03: return model.Resource(tile, model.MOUNTAIN) else: return None elif tile.tileId == model.PLAINS: # plains probability distribution: # None: 80% # Wheat: 20% randomNum = random() if randomNum > 0.8: return model.Resource(tile, model.WHEAT) else: return None elif tile.tileId == model.TUNDRA: # plains probability distribution: # None: 85% # Mountain: 15% randomNum = random() if randomNum > 0.85: return model.Resource(tile, model.MOUNTAIN) else: return None else: return None