2009-04-19 11:42:48 +00:00
|
|
|
from lxml import html
|
2009-04-17 03:52:47 +00:00
|
|
|
import urllib
|
2009-04-17 03:53:59 +00:00
|
|
|
|
2009-07-08 17:04:30 +00:00
|
|
|
from util import hook
|
2009-04-17 03:52:47 +00:00
|
|
|
|
2009-04-18 00:57:18 +00:00
|
|
|
|
2009-04-23 02:49:06 +00:00
|
|
|
@hook.command('u')
|
|
|
|
@hook.command
|
2009-04-17 03:52:47 +00:00
|
|
|
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-19 11:42:48 +00:00
|
|
|
page = html.parse(url)
|
2009-07-21 20:13:35 +00:00
|
|
|
words = page.xpath("//td[@class='word']")
|
2009-04-17 03:52:47 +00:00
|
|
|
defs = page.xpath("//div[@class='definition']")
|
|
|
|
|
|
|
|
if not defs:
|
|
|
|
return 'no definitions found'
|
|
|
|
|
2009-07-21 20:14:29 +00:00
|
|
|
out = words[0].text_content().strip() + ': ' + ' '.join(
|
2009-07-21 20:13:35 +00:00
|
|
|
defs[0].text_content().split())
|
2009-04-17 03:52:47 +00:00
|
|
|
|
|
|
|
if len(out) > 400:
|
|
|
|
out = out[:out.rfind(' ', 0, 400)] + '...'
|
|
|
|
|
|
|
|
return out
|