This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
2013-02-06 13:03:18 +01:00
|
|
|
from util import hook, web, text
|
|
|
|
|
|
|
|
|
|
|
|
@hook.command
|
|
|
|
def answer(inp):
|
2013-09-04 12:30:04 +02:00
|
|
|
"""answer <query> -- find the answer to a question on Yahoo! Answers"""
|
2013-02-06 13:03:18 +01:00
|
|
|
|
|
|
|
query = "SELECT Subject, ChosenAnswer, Link FROM answers.search WHERE query=@query LIMIT 1"
|
|
|
|
result = web.query(query, {"query": inp.strip()}).one()
|
|
|
|
|
2013-08-06 01:13:50 +02:00
|
|
|
short_url = web.try_isgd(result["Link"])
|
2013-02-06 13:03:18 +01:00
|
|
|
|
2013-02-07 07:55:53 +01:00
|
|
|
# we split the answer and .join() it to remove newlines/extra spaces
|
2014-02-13 03:02:44 +01:00
|
|
|
answer_text = text.truncate_str(' '.join(result["ChosenAnswer"].split()), 80)
|
2013-02-07 07:55:53 +01:00
|
|
|
|
2014-02-13 03:02:44 +01:00
|
|
|
return u'\x02{}\x02 "{}" - {}'.format(result["Subject"], answer_text, short_url)
|