Created
February 14, 2016 15:30
-
-
Save posobin/c65d23beaf516654cb49 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
import json | |
import fileinput | |
import urllib.request | |
import sys | |
key = "" | |
url = "https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=" + \ | |
key + \ | |
"&lang=en-ru&text=" | |
count = 0 | |
for word in fileinput.input(): | |
response = urllib.request.urlopen(url + word) | |
data = json.loads(response.read().decode('utf-8')) | |
meanings = [] | |
count += 1 | |
if len(data['def']) == 0: | |
continue | |
for array in data['def']: | |
for translation in array['tr']: | |
meanings.append(translation['text']) | |
print(word.strip() + ' $ ' + ', '.join(meanings[:4])) | |
if count % 50 == 0: | |
print(str(count), file=sys.stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment