make urbandictionary say word name

This commit is contained in:
Ryan Hitchman 2009-07-21 14:13:35 -06:00
parent 1c177e12b8
commit 43e9303ba4
1 changed files with 3 additions and 1 deletions

View File

@ -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)] + '...'