Created
May 9, 2015 13:37
-
-
Save tieorange/b5706d335504e9222940 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 urllib import request | |
import json | |
def translate_from_polish_to_english(word_to_translate): | |
req = request.urlopen( | |
'https://glosbe.com/gapi/translate?from=pol&dest=eng&format=json&phrase=%s' % word_to_translate) | |
encoding = req.headers.get_content_charset() | |
json_result = json.loads(req.read().decode(encoding)) | |
translated_word = json_result['tuc'][0]['meanings'][0]['text'] | |
# print(translated_word) | |
return translated_word | |
def translate_from_en_to_pl(word_to_translate): | |
req = request.urlopen( | |
'https://glosbe.com/gapi/translate?from=eng&dest=pol&format=json&phrase=%s' % word_to_translate) | |
encoding = req.headers.get_content_charset() | |
json_result = json.loads(req.read().decode(encoding)) | |
translated_word = json_result['tuc'][0]['phrase']['text'] | |
# print(translated_word) | |
return translated_word | |
print(translate_from_polish_to_english('kurwa')) | |
print(translate_from_en_to_pl('fuck')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment