Skip to content

Instantly share code, notes, and snippets.

@itarato
Created January 19, 2015 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarato/b4189783a09f5922dde7 to your computer and use it in GitHub Desktop.
Save itarato/b4189783a09f5922dde7 to your computer and use it in GitHub Desktop.
Translate EN -> HU
import sys
import urllib2
import re
import HTMLParser
def lookup(word_en, limit = 10):
url = 'http://szotar.sztaki.hu/search?fromlang=eng&tolang=hun&searchWord=' + word_en + '&langcode=hu&u=0&langprefix=&searchMode=WORD_PREFIX&viewMode=full&ignoreAccents=0'
result = urllib2.urlopen(url)
h = HTMLParser.HTMLParser()
for line in result:
matches = re.findall('<a class="[^"]*prop_content[^>]*>([^<]*)<\/a>', line, re.MULTILINE)
if matches:
for match in matches:
print(h.unescape(match))
limit -= 1
if limit <= 0:
return
if __name__ == '__main__':
if len(sys.argv) < 2:
print('Missing arg. Call: $ python en2hu.py WORD [LIMIT]')
sys.exit(1)
word_en = sys.argv[1]
if len(sys.argv) >= 3:
limit = int(sys.argv[2])
else:
limit = 10
lookup(word_en, limit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment