當前位置: 首頁>>代碼示例>>Python>>正文


Python html2text.html2text方法代碼示例

本文整理匯總了Python中html2text.html2text方法的典型用法代碼示例。如果您正苦於以下問題:Python html2text.html2text方法的具體用法?Python html2text.html2text怎麽用?Python html2text.html2text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在html2text的用法示例。


在下文中一共展示了html2text.html2text方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: send_email

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def send_email(to_address, subject, html_body):
        try:
            smtp = EmailService.create_smtp_server()
            message = mailer.Message(
                From=EmailService.__from_address,
                To=to_address,
                charset='utf-8')
            message.Subject = subject
            message.Html = html_body
            message.Body = html2text.html2text(html_body)

            if not EmailService.__is_debug_mode:
                print("Sending message (live!)")
                smtp.send(message)
            else:
                print("Skipping send, email is in dev mode.")
        except Exception as x:
            print("Error sending mail: {}".format(x)) 
開發者ID:mikeckennedy,項目名稱:python-for-entrepreneurs-course-demos,代碼行數:20,代碼來源:email_service.py

示例2: echo_html_list_str

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def echo_html_list_str(self, catid, infos):
        '''
        生成 list 後的 HTML 格式的字符串
        '''
        zhiding_str = ''
        tuiguang_str = ''
        imgname = 'fixed/zhanwei.png'

        kwd = {
            'imgname': imgname,
            'zhiding': zhiding_str,
            'tuiguang': tuiguang_str,
        }

        self.render('autogen/infolist/infolist_{0}.html'.format(catid),
                    userinfo=self.userinfo,
                    kwd=kwd,
                    html2text=html2text,
                    post_infos=infos,
                    widget_info=kwd) 
開發者ID:bukun,項目名稱:TorCMS,代碼行數:22,代碼來源:filter_handler.py

示例3: do_for_post

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def do_for_post(rand=True, doc_type=''):
    if rand:
        recs = MPost.query_random(num=10, kind='1')
    else:
        recs = MPost.query_recent(num=2, kind='1')

    for rec in recs:
        text2 = rec.title + ',' + html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))
        writer = TOR_IDX.writer()
        writer.update_document(
            title=rec.title,
            catid='sid1',
            type=doc_type,
            link='/post/{0}'.format(rec.uid),
            content=text2,
        )
        writer.commit() 
開發者ID:bukun,項目名稱:TorCMS,代碼行數:19,代碼來源:run_whoosh.py

示例4: do_for_wiki

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def do_for_wiki(rand=True, doc_type=''):
    if rand:
        recs = MWiki.query_random(num=10, kind='1')
    else:
        recs = MWiki.query_recent(num=2, kind='1')

    for rec in recs:
        text2 = rec.title + ',' + html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))

        writer = TOR_IDX.writer()
        writer.update_document(
            title=rec.title,
            catid='sid1',
            type=doc_type,
            link='/wiki/{0}'.format(rec.title),
            content=text2
        )
        writer.commit() 
開發者ID:bukun,項目名稱:TorCMS,代碼行數:20,代碼來源:run_whoosh.py

示例5: mediawiki2markdown

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def mediawiki2markdown(source):
    try:
        import html2text
        from mediawiki import wiki2html
    except ImportError:
        raise ImportError("""This operation requires GPL libraries:
        "mediawiki" (https://pypi.org/project/mediawiki2html/)
        "html2text" (https://pypi.org/project/html2text/)""")

    html2text.BODY_WIDTH = 0

    wiki_content = wiki2html(source, True)
    wiki_content = _convert_toc(wiki_content)
    markdown_text = html2text.html2text(wiki_content)
    markdown_text = markdown_text.replace('<', '&lt;').replace('>', '&gt;')
    return markdown_text 
開發者ID:apache,項目名稱:allura,代碼行數:18,代碼來源:converters.py

示例6: send

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def send(self, to: str, context: dict = None):
        """
        Send a confirm email/welcome email/goodbye email to a subscriber.
        If the SubscriptionFormTemplate instance is not an email, it will raise
        an FormTemplateIsNotEmail exception.

        :param to: Subscriber email address
        :param context: Extra context to be used during email rendering
        """
        if not self.is_email:
            raise FormTemplateIsNotEmail

        rich_text_message = self.render_template(context)
        plain_text_message = html2text.html2text(rich_text_message, bodywidth=2000)
        email = EmailMultiAlternatives(
            subject=self.subject,
            body=plain_text_message,
            from_email=self.get_from_email(),
            to=[to]
        )
        email.attach_alternative(rich_text_message, 'text/html')
        email.send() 
開發者ID:vitorfs,項目名稱:colossus,代碼行數:24,代碼來源:models.py

示例7: check_grammar

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def check_grammar(self, file_name):
        """Check the grammar of the specified file

           Parameters
           -----------
           file_name: name of the file to be checked
        """
        file_content = html2text.html2text(open(file_name).read())
        file_content = re.sub(u"[\x00-\x08\x0b-\x0c\x0e-\x1f]+", u"", file_content)
        self.__grammar_check_res = self.__grammar_checker.check(file_content) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:12,代碼來源:doc_spell_checker.py

示例8: send_shelf_audit_email

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def send_shelf_audit_email(shelf):
  """Sends a shelf audit email.

  Args:
    shelf: shelf_model.Shelf object for location details.

  Raises:
    SendEmailError: if the data pertaining to the audit is incomplete.
  """
  timedelta_since_audit = datetime.datetime.utcnow() - shelf.last_audit_time
  template_dict = {
      'friendly_name': shelf.friendly_name,
      'hours_since_audit': int(timedelta_since_audit.total_seconds() / 3600),
      'location': shelf.location,
      'origin': constants.ORIGIN,
  }
  title, body = constants.TEMPLATE_LOADER.render(
      'shelf_audit_request', template_dict)
  email_dict = {
      'to': config_model.Config.get('shelf_audit_email_to'),
      'subject': title,
      'body': html2text.html2text(body),
      'html': body,
  }
  # We want each different subject to generate a unique hash.
  logging.info(
      'Sending email to %s\nSubject: %s.', shelf.responsible_for_audit, title)
  _send_email(**email_dict) 
開發者ID:google,項目名稱:loaner,代碼行數:30,代碼來源:send_email.py

示例9: _transform_attack

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def _transform_attack(attack) -> Attack:
        desc = attack['desc'] and html2text.html2text(attack['desc'], bodywidth=0).strip()

        if attack['saveDc'] is not None and attack['saveStat'] is not None:
            stat = constants.STAT_ABBREVIATIONS[attack['saveStat'] - 1]
            for_half = desc and 'half' in desc

            the_attack = automation.Save(
                stat,
                fail=[automation.Damage("{damage}")],
                success=[] if not for_half else [automation.Damage("{damage}/2")],
                dc=str(attack['saveDc'])
            )

            # attack, then save
            if attack['toHit'] is not None:
                the_attack = automation.Attack(hit=[the_attack], attackBonus=str(attack['toHit']), miss=[])

            # target and damage meta
            target = automation.Target('each', [the_attack])
            target.meta = [automation.Roll(attack['damage'] or '0', 'damage')]
            effects = [target]
            # description text
            if desc:
                effects.append(automation.Text(desc))

            return Attack(attack['name'], automation.Automation(effects))
        else:
            return Attack.new(attack['name'], attack['toHit'], attack['damage'] or '0', desc) 
開發者ID:avrae,項目名稱:avrae,代碼行數:31,代碼來源:beyond.py

示例10: html2text

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def html2text(html: str) -> str:
    return _html2text(html) 
開發者ID:kevinzg,項目名稱:facebook-scraper,代碼行數:4,代碼來源:utils.py

示例11: parse_html

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def parse_html(html):
    '''
    Parse HTML and convert it into a udata-compatible markdown string
    '''
    if not html:
        return ''
    return html2text.html2text(html.strip(), bodywidth=0).strip() 
開發者ID:opendatateam,項目名稱:udata,代碼行數:9,代碼來源:markdown.py

示例12: render

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def render(self, *args, **kwargs):

        # info = args[0]

        info = kwargs.get('info', args[0])
        zhiding_str = ''
        tuiguang_str = ''
        imgname = 'fixed/zhanwei.png'
        if info.extinfo['mymps_img']:
            imgname = info.extinfo['mymps_img'][0]
        if info.extinfo['def_zhiding'] == 1:
            zhiding_str = '<span class="red">(已置頂)</span>'
        if info.extinfo['def_tuiguang'] == 1:
            tuiguang_str = '<span class="red">(已推廣)</span>'

        list_type = info.extinfo['catid']

        kwd = {
            'imgname': imgname,
            'zhiding': zhiding_str,
            'tuiguan': tuiguang_str,
        }

        return self.render_string('infor/infolist/infolist_{0}.html'.format(list_type),
                                  kwd=kwd,
                                  html2text=html2text,
                                  post_info=info) 
開發者ID:bukun,項目名稱:TorCMS,代碼行數:29,代碼來源:info_modules.py

示例13: html2markdown

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def html2markdown(html: str) -> str:
    """
    Returns the given HTML as equivalent Markdown-structured text.
    """
    try:
        return pypandoc.convert_text(html, 'md', format='html')
    except OSError:
        msg = "It's recommended to install the `pandoc` library for converting " \
              "HTML into Markdown-structured text. It tends to have better results" \
              "than `html2text`, which is now used as a fallback."
        print(msg)
        return html2text(html) 
開發者ID:Debakel,項目名稱:feedDiasp,代碼行數:14,代碼來源:RSSParser.py

示例14: html2text

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def html2text(message):
    try:
        from html2text import html2text

        return html2text(message)
    except ImportError:
        return strip_tags(message) 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:9,代碼來源:utils.py

示例15: clean_html

# 需要導入模塊: import html2text [as 別名]
# 或者: from html2text import html2text [as 別名]
def clean_html(message):
    from dbmail.defaults import MESSAGE_HTML2TEXT

    module = import_module(MESSAGE_HTML2TEXT)
    return module.html2text(message) 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:7,代碼來源:utils.py


注:本文中的html2text.html2text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。