| ''' |
| Example Action feed for Google Order Redirect.Create "generated" directory for generated proto classes. |
| Download lastest version of protoc from https://github.com/protocolbuffers/protobuf/releases |
| Generate proto classes with: |
| protoc --python_out=./generated --proto_path=../proto/ ../proto/entity.proto |
| |
| See https://protobuf.dev/reference/python/python-generated/ for more details. |
| ''' |
| |
| import json |
| from generated import entity_pb2 |
| from google.protobuf.json_format import MessageToDict |
| |
| def create_feed() -> str: |
| # Create feeds |
| feed = entity_pb2.EntityFeed() |
| |
| # Create entity and add to feed data |
| entity = feed.data.add() |
| entity.entity_id = 'merchant-1' |
| entity.name = "Mo's Dinner" |
| entity.telephone = '+14567891234' |
| entity.url = 'http://moesdinner.com' |
| |
| # Create location |
| location = entity.location |
| location.latitude = 41.525588 |
| location.longitude = -90.507067 |
| |
| # Create address |
| address = location.address |
| address.country = 'US' |
| address.locality = 'Mountain View' |
| address.region = 'CA' |
| address.postal_code = '94043' |
| address.street_address = '1600 Amphitheatre Pkwy' |
| |
| # Serialize feed to JSON string |
| return json.dumps(MessageToDict(feed, preserving_proto_field_name=True)) |
| |
| feedJSON = create_feed() |
| print(feedJSON) |
| |