本文整理汇总了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))
示例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)
示例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()
示例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()
示例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('<', '<').replace('>', '>')
return markdown_text
示例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()
示例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)
示例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)
示例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)
示例10: html2text
# 需要导入模块: import html2text [as 别名]
# 或者: from html2text import html2text [as 别名]
def html2text(html: str) -> str:
return _html2text(html)
示例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()
示例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)
示例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)
示例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)
示例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)