Files
backend-v1/core/services/grpc/auto.py
xoliqberdiyev 7961fd76de add grpc client
2026-04-23 17:36:43 +05:00

49 lines
1.2 KiB
Python

import grpc
from google.protobuf.timestamp_pb2 import Timestamp
from datetime import datetime
from config.env import env
from core.generated import auto_pb2, auto_pb2_grpc
def get_auto_avg_cost(
brand,
condition,
model,
complication,
manufacture_date: datetime,
distance_covered,
color
):
# url = f"{env.str('RPC_IP')}:{env.str('RPC_PORT')}"
# channel = grpc.insecure_channel(url)
channel = grpc.insecure_channel("192.168.1.120:50051")
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
ts = Timestamp()
ts.FromDatetime(manufacture_date)
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
brand=brand,
condition=condition,
model=model,
complication=complication,
manufacture_date=ts,
distance_covered=distance_covered,
color=color,
))
return {
"avg_cost": response.avg_cost,
"ads": [
{
"id": ad.id,
"title": ad.title,
"price": ad.price,
"model": ad.model,
"images": [img.image for img in ad.images],
}
for ad in response.ads
]
}