Fixed URL, small tweaks
This commit is contained in:
parent
61dd81cf36
commit
d2260bc5d8
1 changed files with 8 additions and 9 deletions
|
@ -1,10 +1,9 @@
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
api_url = "http://encyclopediadramatica.ch/api.php?action=opensearch"
|
api_url = "http://encyclopediadramatica.se/api.php?action=opensearch"
|
||||||
ed_url = "http://encyclopediadramatica.ch/"
|
ed_url = "http://encyclopediadramatica.se/"
|
||||||
|
|
||||||
|
|
||||||
@hook.command('ed')
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def drama(inp):
|
def drama(inp):
|
||||||
".drama <phrase> -- Gets the first paragraph of" \
|
".drama <phrase> -- Gets the first paragraph of" \
|
||||||
|
@ -12,7 +11,7 @@ def drama(inp):
|
||||||
|
|
||||||
j = http.get_json(api_url, search=inp)
|
j = http.get_json(api_url, search=inp)
|
||||||
if not j[1]:
|
if not j[1]:
|
||||||
return 'no results found'
|
return "No results found."
|
||||||
article_name = j[1][0].replace(' ', '_').encode('utf8')
|
article_name = j[1][0].replace(' ', '_').encode('utf8')
|
||||||
|
|
||||||
url = ed_url + http.quote(article_name, '')
|
url = ed_url + http.quote(article_name, '')
|
||||||
|
@ -20,9 +19,9 @@ def drama(inp):
|
||||||
|
|
||||||
for p in page.xpath('//div[@id="bodyContent"]/p'):
|
for p in page.xpath('//div[@id="bodyContent"]/p'):
|
||||||
if p.text_content():
|
if p.text_content():
|
||||||
summary = ' '.join(p.text_content().splitlines())
|
summary = " ".join(p.text_content().splitlines())
|
||||||
if len(summary) > 300:
|
if len(summary) > 300:
|
||||||
summary = summary[:summary.rfind(' ', 0, 300)] + "..."
|
summary = summary[:summary.rfind(' ', 0, 300)] + "..."
|
||||||
return '%s :: \x02%s\x02' % (summary, url)
|
return "%s :: \x02%s\x02" % (summary, url)
|
||||||
|
|
||||||
return "error"
|
return "Unknown Error."
|
||||||
|
|
Reference in a new issue