Skip to content

Instantly share code, notes, and snippets.

@posobin
Created February 14, 2016 15:30
Show Gist options
  • Save posobin/c65d23beaf516654cb49 to your computer and use it in GitHub Desktop.
Save posobin/c65d23beaf516654cb49 to your computer and use it in GitHub Desktop.
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