Last active
April 24, 2018 21:11
-
-
Save giacaglia/e1e1e4e9077974fdaf1dbd45a10db10c to your computer and use it in GitHub Desktop.
Transform entities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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