2010-03-05 05:15:29 +00:00
|
|
|
'''Searches Encyclopedia Dramatica and returns the first paragraph of the
|
2010-03-03 18:11:52 +00:00
|
|
|
article'''
|
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
from util import hook, http
|
2010-03-04 05:30:54 +00:00
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
api_url = "http://encyclopediadramatica.com/api.php?action=opensearch"
|
2010-03-05 05:15:29 +00:00
|
|
|
ed_url = "http://encyclopediadramatica.com/"
|
2010-03-03 18:11:52 +00:00
|
|
|
|
|
|
|
|
2010-03-13 06:16:06 +00:00
|
|
|
@hook.command('ed')
|
2010-03-03 18:11:52 +00:00
|
|
|
@hook.command
|
|
|
|
def drama(inp):
|
2010-03-04 05:30:54 +00:00
|
|
|
'''.drama <phrase> -- gets first paragraph of Encyclopedia Dramatica ''' \
|
|
|
|
'''article on <phrase>'''
|
2010-08-30 03:35:27 +00:00
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
j = http.get_json(api_url, search=inp)
|
2010-03-04 05:30:54 +00:00
|
|
|
if not j[1]:
|
|
|
|
return 'no results found'
|
2010-04-23 03:47:41 +00:00
|
|
|
article_name = j[1][0].replace(' ', '_').encode('utf8')
|
2010-03-27 08:42:27 +00:00
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
url = ed_url + http.quote(article_name, '')
|
|
|
|
page = http.get_html(url)
|
2010-03-27 08:42:27 +00:00
|
|
|
|
2010-03-04 05:30:54 +00:00
|
|
|
for p in page.xpath('//div[@id="bodyContent"]/p'):
|
|
|
|
if p.text_content():
|
|
|
|
summary = ' '.join(p.text_content().splitlines())
|
|
|
|
if len(summary) > 300:
|
|
|
|
summary = summary[:summary.rfind(' ', 0, 300)] + "..."
|
|
|
|
return '%s :: \x02%s\x02' % (summary, url)
|
|
|
|
|
|
|
|
return "error"
|