2009-04-17 03:53:59 +00:00
|
|
|
import lxml
|
2009-04-17 03:52:47 +00:00
|
|
|
import urllib
|
2009-04-17 03:53:59 +00:00
|
|
|
|
2009-04-17 03:52:47 +00:00
|
|
|
import hook
|
|
|
|
|
|
|
|
@hook.command('u')
|
|
|
|
@hook.command
|
|
|
|
def urban(inp):
|
|
|
|
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
|
|
|
|
if not inp.strip():
|
|
|
|
return urban.__doc__
|
|
|
|
|
|
|
|
url = 'http://www.urbandictionary.com/define.php?term=' + \
|
|
|
|
urllib.quote(inp.strip(), safe='')
|
2009-04-17 03:53:59 +00:00
|
|
|
page = lxml.html.parse(url)
|
2009-04-17 03:52:47 +00:00
|
|
|
defs = page.xpath("//div[@class='definition']")
|
|
|
|
|
|
|
|
if not defs:
|
|
|
|
return 'no definitions found'
|
|
|
|
|
|
|
|
out = ' '.join(defs[0].text_content().split())
|
|
|
|
|
|
|
|
if len(out) > 400:
|
|
|
|
out = out[:out.rfind(' ', 0, 400)] + '...'
|
|
|
|
|
|
|
|
return out
|