add .etymology, courtesy of GhettoWizard

This commit is contained in:
Ryan Hitchman 2010-05-11 16:48:05 -06:00
parent b845bfcf25
commit 49ba4c5753
1 changed files with 24 additions and 0 deletions

View File

@ -84,3 +84,27 @@ def define(inp):
result = re.sub(r'[^A-Za-z]+\.?$', '', result) + ' ...'
return result
@hook.command('e')
@hook.command
def etymology(inp):
".e/.etymology <word> -- Retrieves the etymology of chosen word"
url = 'http://www.etymonline.com/index.php'
h = http.get_html(url, term=inp)
etym = h.xpath('//dl')
if not etym:
return 'No etymology found for ' + inp
etym = etym[0].text_content()
etym = ' '.join(etym.split())
if len(etym) > 400:
etym = etym[:etym.rfind(' ', 0, 400)] + ' ...'
return etym