Skip to content

Instantly share code, notes, and snippets.

@giacaglia
Last active April 24, 2018 21:11
Show Gist options
  • Save giacaglia/e1e1e4e9077974fdaf1dbd45a10db10c to your computer and use it in GitHub Desktop.
Save giacaglia/e1e1e4e9077974fdaf1dbd45a10db10c to your computer and use it in GitHub Desktop.
Transform entities
def transform_entity(pb):
from google.cloud.datastore.helpers import entity_from_protobuf
entity = entity_from_protobuf(pb)
retailer_id = entity.get('id', '')
name = entity.get('name')
category = entity.get(‘category’, ‘’)
description = entity.get(‘description’, ‘’)
image_link = entity.get(‘image’, ‘’)
price = entity.get(‘price’, ‘0’)
link = entity.get('url', '')
return {
‘id’: retailer_id,
‘title’: name,
‘category’: category,
‘description’: description,
‘image_link’: image_link,
‘name’: name,
‘price’: price,
‘retailer_id’: retailer_id,
‘link’: link
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment