Files
backend-v1/core/services/grpc/auto.py
xoliqberdiyev 7134b2c185 add new api
2026-04-27 14:50:59 +05:00

55 lines
1.3 KiB
Python

from datetime import datetime
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
):
channel = grpc.insecure_channel("94.230.232.47:50051")
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
ts = Timestamp()
if isinstance(manufacture_date, datetime):
dt = manufacture_date
else:
dt = datetime.combine(manufacture_date, datetime.min.time())
ts.FromDatetime(dt)
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
brand=brand,
condition=condition,
model=model,
complication=complication,
manufacture_date=ts,
distance_covered=distance_covered,
color=color,
))
print("manufacture_date:", manufacture_date, type(manufacture_date))
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
]
}