Skip to content

Instantly share code, notes, and snippets.

@meoyawn
Created April 22, 2017 14:06
Show Gist options
  • Save meoyawn/ee82356791cfc8c935aaa455826450f6 to your computer and use it in GitHub Desktop.
Save meoyawn/ee82356791cfc8c935aaa455826450f6 to your computer and use it in GitHub Desktop.
translate between tatar and russian from CLI
#!/usr/bin/env python3
import sys
from urllib.parse import quote
from lxml import html
if len(sys.argv) > 1:
word = sys.argv[1]
url = "http://tatpoisk.net/dict/" + quote(word)
results = html.parse(url).getroot().cssselect(".search_results")
if results:
translation = results[0].text_content()
print(translation)
else:
print("could not translate", word)
else:
print("please specify your word")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment