make urbandictionary say word name
This commit is contained in:
parent
1c177e12b8
commit
43e9303ba4
|
@ -14,12 +14,14 @@ def urban(inp):
|
||||||
url = 'http://www.urbandictionary.com/define.php?term=' + \
|
url = 'http://www.urbandictionary.com/define.php?term=' + \
|
||||||
urllib.quote(inp.strip(), safe='')
|
urllib.quote(inp.strip(), safe='')
|
||||||
page = html.parse(url)
|
page = html.parse(url)
|
||||||
|
words = page.xpath("//td[@class='word']")
|
||||||
defs = page.xpath("//div[@class='definition']")
|
defs = page.xpath("//div[@class='definition']")
|
||||||
|
|
||||||
if not defs:
|
if not defs:
|
||||||
return 'no definitions found'
|
return 'no definitions found'
|
||||||
|
|
||||||
out = ' '.join(defs[0].text_content().split())
|
out = words[0].text_content().strip() + ' '.join(
|
||||||
|
defs[0].text_content().split())
|
||||||
|
|
||||||
if len(out) > 400:
|
if len(out) > 400:
|
||||||
out = out[:out.rfind(' ', 0, 400)] + '...'
|
out = out[:out.rfind(' ', 0, 400)] + '...'
|
||||||
|
|
Loading…
Reference in New Issue