| ''' |
| Example Service 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: |
| mkdir generated |
| protoc --python_out=./generated --proto_path=../proto/ ../proto/*.proto ../proto/google/type/*.proto |
| |
| See https://protobuf.dev/reference/python/python-generated/ for more details. |
| ''' |
| |
| import json |
| from generated import food_service_pb2 |
| from generated.google.type import timeofday_pb2 |
| from google.protobuf.json_format import MessageToDict |
| |
| def create_feed() -> str: |
| # Create feed |
| feed = food_service_pb2.FoodServiceFeed() |
| |
| # Create delivery service |
| delivery_service_data = feed.data.add() |
| delivery_service_data.service.service_id = 'merchant-1-service-delivery' |
| delivery_service_data.service.service_type = food_service_pb2.FoodOrderingService.ServiceType.DELIVERY |
| delivery_service_data.service.parent_entity_id = 'merchant-1' |
| delivery_service_data.service.lead_time.min_lead_time_duration.seconds = 60*20 |
| delivery_service_data.service.lead_time.min_lead_time_duration.seconds = 60*30 |
| delivery_service_data.service.action_link_id = 'merchant-1-takeout-delivery-action' |
| |
| # Create fee |
| fee_data = feed.data.add() |
| fee_data.fee.fee_id = 'merchant-1-fee-delivery' |
| fee_data.fee.fee_type = food_service_pb2.Fee.FeeType.DELIVERY |
| fee_data.fee.fixed_amount.currency_code = 'USD' |
| fee_data.fee.fixed_amount.units = 2 |
| fee_data.fee.service_ids.append('merchant-1-service-delivery') |
| |
| # Create asap service hours |
| asap_hours_data = feed.data.add() |
| asap_hours_data.service_hours.hours_id = 'merchant-1-asap-hours-delivery' |
| asap_hours_data.service_hours.service_ids.append('merchant-1-service-delivery') |
| asap_hours = asap_hours_data.service_hours.asap_hours.add() |
| asap_hours.time_windows.CopyFrom(food_service_pb2.TimeOfDayWindow( |
| time_windows=food_service_pb2.TimeOfDayRange( |
| open_time=timeofday_pb2.TimeOfDay( |
| hours=11, |
| minutes=0 |
| ), |
| close_time=timeofday_pb2.TimeOfDay( |
| hours=22, |
| minutes=30 |
| ) |
| ) |
| ) |
| ) |
| asap_hours.lead_time.min_lead_time_duration.seconds = 2400 |
| |
| |
| # Create service area |
| service_area_data = feed.data.add() |
| service_area_data.service_area.area_id = 'merchant-1-area-delivery' |
| service_area_data.service_area.service_ids.append('merchant-1-service-delivery') |
| service_area_data.service_area.circle.center.latitude = 37.4215576 |
| service_area_data.service_area.circle.center.longitude = -122.0951056 |
| service_area_data.service_area.circle.radius = 5000 |
| |
| # Serialize to JSON string |
| return json.dumps(MessageToDict(feed, preserving_proto_field_name=True)) |
| |
| feedJSON = create_feed() |
| print(feedJSON) |