Skip to content

Instantly share code, notes, and snippets.

@valpackett
Created March 17, 2011 19:09
Show Gist options
  • Save valpackett/874927 to your computer and use it in GitHub Desktop.
Save valpackett/874927 to your computer and use it in GitHub Desktop.
Yandex.Anthroponym client

Yandex.Anthroponym is a web service which translates names from English to Russian and vice versa. This is a little script (designed for TextExpander, but works fine in a shell) which gets the current Mac OS X clipboard content, translates it and prints back the output.

So you have copied "Ray William Johnson", for example. Type the abbreviation you've defined in TextExpander and "Рей Вильям Джонсон" will be pasted.

If you don't have PyPy (you should, it's really fast), change the first line to "#!/usr/bin/env python". Don't forget to pip install requests. And, of course, to set snippet type to "Shell Script" when adding to TextExpander.

#!/usr/local/bin/pypy
import os
import sys
sys.path.append('/Library/Python/2.6/site-packages')
import requests
import urllib
import simplejson
import os
sys.stdout.write(simplejson.loads(requests.get('http://nano.yandex.ru/project/anthroponym/do/?query='+urllib.quote(os.popen('pbpaste').read())).content)['antroponyms'][0]['trn'].encode('utf-8', 'ignore'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment