def lookup_verse(self, query, book=None): """Lookup specified verse""" if book is None: book = self.DEFAULT_BIBLE elif book not in self.bibles: return u"Unknown bible.. why do you hate god so much?" opts = {"search": query, "version": book} soup = self.getsoup(self.bg_search, opts, referer=self.bg_search) passage = soup.find("div", {"class": re.compile("passage-content")}) for name in "heading passage-class-0", "publisher-info-bottom": junk = passage.find("div", name) if junk is not None: junk.extract() response = [] for para in passage("p"): response.append(para.renderContents()) res = decode(" ".join(response), "utf-8") # convert superscript verse markers to unicode while True: match = self.sup_re.search(res) if not match: break res = res.replace(match.group(0), superscript(match.group(1))) # XXX this is like this for a reason res = strip_html(res).replace(u"\xa0", u" ") while u" " in res: res = res.replace(u" ", u" ") res = res.strip() return res
def lookup_verse(self, query, book=None): """Lookup specified verse""" if book is None: book = self.DEFAULT_BIBLE elif book not in self.bibles: return u'Unknown bible.. why do you hate god so much?' opts = {'search': query, 'version': book} soup = getsoup(self.bg_search, opts, referer=self.bg_search) passage = soup.find('div', 'passage-wrap') for name in 'heading passage-class-0', 'publisher-info-bottom': passage.find('div', name).extract() response = [] for para in passage('p'): response.append(para.renderContents()) res = decode(' '.join(response), 'utf-8') # convert superscript verse markers to unicode while True: match = self.sup_re.search(res) if not match: break res = res.replace(match.group(0), superscript(match.group(1))) # XXX this is like this for a reason res = strip_html(res).replace(u'\xa0', u' ') while u' ' in res: res = res.replace(u' ', u' ') res = res.strip() return res
def calculator(self, query): """Try to use google calculator for given query""" opts = dict(self.calcopts) opts[u'q'] = query doc = self.ua.open(self.search, opts=opts) soup = BeautifulSoup(doc) response = soup.find('img', src=self.calc_re).parent.findNext('h2').renderContents() response = ' '.join(response.splitlines()) response = response.decode('utf-8', 'ignore') # turn super scripts into utf8 parts = [] for part in self.sup_re.split(response): if self.sup_re.match(part): part = superscript(part) parts.append(part) response = u''.join(parts) response = self.white_re.sub(' ', strip_html(response).strip()) return response