Translator-GO-Endpoint/scripts/python/create_response.py

19 lines
524 B
Python
Raw Normal View History

import json
from datetime import datetime, timezone
def create_respone(translated, from_code, to_code, error):
# Creating a dictionary that matches the structure of your JSON
data = {
"from": from_code,
"to": to_code,
"created_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z"),
"response": translated,
"error": error
}
json_string = json.dumps(data, indent=4)
# Printing the JSON string to the console
print(json_string)