Created
June 14, 2020 13:08
-
-
Save Burekasim/07e9b99de1ea81815552bf8a0c914a52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from googletrans import Translator | |
from urllib.parse import unquote | |
def lambda_handler(event, context): | |
data = event['body'].split('&') | |
body = '' | |
for item in data: | |
tt = item.split('=') | |
if tt[0] == 'Body': | |
body = tt[1] | |
translator = Translator() | |
if any("\u0590" <= c <= "\u05EA" for c in unquote(body)): | |
text = translator.translate(unquote(body), dest='en') | |
print(3) | |
else: | |
text = translator.translate(body, dest='he') | |
return_text = '<?xml version="1.0" encoding="UTF-8"?>\n\ | |
<Response>\n\ | |
<Message>' + text.text + '</Message>\n\ | |
</Response>' | |
return {'statusCode': 200, 'headers': {'Content-Type': 'text/xml', }, 'body': return_text} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment