in dialogflow-prebuilt-agents/cloud-functions/retail_assistant/main.py [0:0]
def get_delivery_date():
"""Get the estimated delivery date"""
app.logger.warning("REACHED /GET_DELIVERY_DATE")
request_json = request.get_json(silent=False)
app.logger.warning("REQUEST: %s", request_json)
shopping_cart = request_json["shopping_cart"]
app.logger.warning("SHOPPING CART: %s", shopping_cart)
# set estimated delivery date between next 3 to 7 days
dt = datetime.now()
td = timedelta(days=random.randint(3, 7))
# your calculated date
est_delivery_date = dt + td
cart_with_delivery_dates = []
for item in shopping_cart:
new_item = item
new_item["delivery_date"] = datetime.strftime(
est_delivery_date, "%B %d, %Y"
)
new_item["earliest_delivery_date"] = datetime.strftime(
est_delivery_date, "%B %d, %Y"
)
cart_with_delivery_dates.append(new_item)
app.logger.warning("CART WITH DELIVERY DATES: %s", cart_with_delivery_dates)
return flask.jsonify({"shopping_cart": cart_with_delivery_dates})