28 lines
674 B
Python
28 lines
674 B
Python
|
import requests
|
||
|
import uuid
|
||
|
from config import Settings
|
||
|
|
||
|
|
||
|
def translate(data):
|
||
|
constructed_url = Settings().AZURE_ENDPOINT + '/translate'
|
||
|
|
||
|
params = {
|
||
|
'api-version': '3.0',
|
||
|
'from': data.language_from,
|
||
|
'to': [data.language_to]
|
||
|
}
|
||
|
|
||
|
headers = {
|
||
|
'Ocp-Apim-Subscription-Key': Settings().AZURE_KEY,
|
||
|
'Ocp-Apim-Subscription-Region': Settings().AZURE_LOCATION,
|
||
|
'Content-type': 'application/json',
|
||
|
'X-ClientTraceId': str(uuid.uuid4())
|
||
|
}
|
||
|
|
||
|
body = [{
|
||
|
'text': data.requested_text
|
||
|
}]
|
||
|
|
||
|
request = requests.post(constructed_url, params=params, headers=headers, json=body)
|
||
|
return request.json()
|