示例#1
0
def get_chapter_html(ref):

    chapter_uid = get_ref_chapter_uid(ref)
    url = core.get_ref_url(ref_uid=chapter_uid)

    entry_key = '{}.html'.format(chapter_uid)
    chapter_html = cache.get_cache_entry_content(entry_key)
    if not chapter_html:
        chapter_html = web.get_url_content(url)
        cache.add_cache_entry(entry_key, chapter_html)

    return chapter_html
示例#2
0
def get_ref_format_value(ref_format, ref):

    return {
        'id': ref_format,
        'name': ref_format.format(
            name=core.get_basic_ref_name(ref),
            version=ref['version'],
            content='Jesus wept.',
            url=core.get_ref_url(ref['uid']))
        .replace('\n', ' ¬ ')
        # Since the above substitution adds whitespace to both sides of the
        # return symbol, the whitespace needs to be collapsed in the case of
        # consecutive return symbols
        .replace('  ', ' ')
    }
def get_ref_format_value(ref_format, ref):

    return {
        'id': ref_format,
        'name': ref_format.format(
            name=core.get_basic_ref_name(ref),
            version=ref['version'],
            content='Jesus wept.',
            url=core.get_ref_url(ref['uid']))
        .replace('\n', ' ¬ ')
        # Since the above substitution adds whitespace to both sides of the
        # return symbol, the whitespace needs to be collapsed in the case of
        # consecutive return symbols
        .replace('  ', ' ')
    }
示例#4
0
def get_ref_content(ref, ref_format, include_verse_numbers):

    chapter_html = get_chapter_html(ref)
    parser = ReferenceParser(ref, include_verse_numbers)
    parser.feed(chapter_html)
    # Format reference content by removing superfluous whitespace and such
    ref_content = core.normalize_ref_content(
        ''.join(parser.content_parts))

    if ref_content:
        copied_content = ref_format.format(
            name=core.get_basic_ref_name(ref),
            version=ref['version'],
            content=ref_content,
            url=core.get_ref_url(ref['uid']))
        return copied_content
    else:
        return ''
def get_result(book, query, chosen_version, user_prefs):

    chapter = min(query['chapter'], book['metadata']['chapters'])
    last_verse = book['metadata']['verses'][chapter - 1]

    result = {}

    # Find chapter if given
    result['uid'] = '{book}.{chapter}'.format(book=book['id'], chapter=chapter)
    result['title'] = '{book} {chapter}'.format(book=book['name'],
                                                chapter=chapter)

    if 'verse' in query:
        verse = min(query['verse'], last_verse)
        result['uid'] += '.{verse}'.format(verse=verse)
        result['title'] += ':{verse}'.format(verse=verse)

    if 'endverse' in query:
        endverse = min(query['endverse'], last_verse)
        if endverse > verse:
            result['uid'] += '-{endverse}'.format(endverse=endverse)
            result['title'] += '-{endverse}'.format(endverse=endverse)

    result['arg'] = '{version}/{uid}'.format(version=chosen_version['id'],
                                             uid=result['uid'])
    result['variables'] = {
        'ref_url': core.get_ref_url(result['arg']),
        'copybydefault': str(user_prefs['copybydefault'])
    }
    result['quicklookurl'] = result['variables']['ref_url']
    result['uid'] = 'yvs-{}'.format(result['arg'])
    result['title'] += ' ({version})'.format(version=chosen_version['name'])
    result['subtitle'] = 'View on YouVersion'
    result['mods'] = {'cmd': {'subtitle': 'Copy content to clipboard'}}

    # Make "Copy" the default action (instead of "View") when the copybydefault
    # preference is set to true
    if user_prefs['copybydefault']:
        result['subtitle'], result['mods']['cmd']['subtitle'] = \
            result['mods']['cmd']['subtitle'], result['subtitle']

    return result
示例#6
0
 def handle_starttag(self, tag, attrs):
     attrs = dict(attrs)
     if 'class' in attrs:
         elem_class = attrs['class']
         # Detect beginning of search result
         if tag == 'li' and elem_class == 'reference':
             self.in_ref = True
             self.current_result = {
                 'arg': '',
                 'title': '',
                 'subtitle': ''
             }
             self.results.append(self.current_result)
     if self.in_ref:
         # Detect beginning of search result heading
         if tag == 'a':
             self.in_heading = True
             self.current_result['arg'] = get_uid_from_url(attrs['href'])
             self.current_result['variables'] = {
                 'ref_url': core.get_ref_url(self.current_result['arg']),
                 'copybydefault': str(self.user_prefs['copybydefault'])
             }
             self.current_result['quicklookurl'] = \
                 self.current_result['variables']['ref_url']
             self.current_result['mods'] = {
                 'cmd': {
                     'subtitle': 'Copy content to clipboard'
                 }
             }
             # Make "Copy" the default action (instead of "View") when the
             # copybydefault preference is set to true
             if self.user_prefs['copybydefault']:
                 self.current_result['mods']['cmd']['subtitle'] = \
                     'View on YouVersion'
         # Detect beginning of search result content
         elif tag == 'p':
             self.in_content = True
示例#7
0
def main(ref_uid):
    print(core.get_ref_url(ref_uid).encode('utf-8'), end=''.encode('utf-8'))