make wolframalpha and urban use apis instead of scraping - commit from Skybot

This commit is contained in:
Luke Rogers 2012-02-16 07:01:41 +13:00
parent b37165b8d2
commit f75aeea2a9
2 changed files with 23 additions and 29 deletions

View file

@ -8,23 +8,20 @@ from util import hook, http
def urban(inp):
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
url = 'http://www.urbandictionary.com/define.php'
page = http.get_html(url, term=inp)
words = page.xpath("//td[@class='word']")
defs = page.xpath("//div[@class='definition']")
url = 'http://www.urbandictionary.com/iphone/search/define'
page = http.get_json(url, term=inp)
defs = page['list']
if not defs:
return 'No definitions found :('
if page['result_type'] == 'no_results':
return 'not found.'
out = '' + words[0].text_content().strip() + ': ' + ' '.join(
defs[0].text_content().split())
out = defs[0]['word'] + ': ' + defs[0]['definition']
if len(out) > 400:
out = out[:out.rfind(' ', 0, 400)] + '...'
return out
# define plugin by GhettoWizard & Scaevolus
@hook.command('dictionary')
@hook.command