From a21f27e64ec31a243fdb0424d660de0e171cf947 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Sat, 10 Apr 2010 16:05:06 -0600 Subject: [PATCH] add koran scraping, courtesy GhettoWizard --- plugins/{bible.py => religion.py} | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) rename plugins/{bible.py => religion.py} (57%) diff --git a/plugins/bible.py b/plugins/religion.py similarity index 57% rename from plugins/bible.py rename to plugins/religion.py index bc41a30..995a216 100644 --- a/plugins/bible.py +++ b/plugins/religion.py @@ -1,5 +1,7 @@ import urllib +from lxml import html + from util import hook @@ -25,3 +27,24 @@ def bible(inp): text = text[:text.rfind(' ', 0, 400)] + '...' return text + +## Koran look-up plugin by Ghetto Wizard + +@hook.command('allah') +@hook.command +def koran(inp): + ".koran -- gets from the Koran" + + if not inp: + return koran.__doc__ + + base_url = 'http://quod.lib.umich.edu/cgi/k/koran/koran-idx?type=simple&q1=' + + raw_data = urllib.urlopen(base_url + urllib.quote(inp, '')).read() + + results = html.fromstring(raw_data).xpath('//li') + + if not results: + return 'No results for ' + inp + + return results[0].text_content()