本文整理汇总了Python中pattern.Pattern.sub方法的典型用法代码示例。如果您正苦于以下问题:Python Pattern.sub方法的具体用法?Python Pattern.sub怎么用?Python Pattern.sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pattern.Pattern
的用法示例。
在下文中一共展示了Pattern.sub方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import sub [as 别名]
def export(self):
"""
"""
logger.debug("Begin RSS Export:")
db = CrawlDB()
rep = Pattern()
for pat in db.getPatterns():
pid = pat["pid"]
pattern = pat["pattern"]
description = pat["name"]
items = []
for page in db.getPages("where pid=%d limit 10" % pid):
items.append(self.rssitem % (page["url"],
page["title"],
"",
pattern,
"",
page["url"],
rep.sub(page["content"])))
itemout = "\n".join(items)
output = self.rssframe % (pattern,
"http://hjbbs.com/bbs",
description,
"Learning English Tool",
itemout)
logger.debug("LET %d:\n%s\n" % (pid, output))
# write out
fp = open("%slet%d.xml" % (config.RSSDIR, pid), "w")
fp.write(output.encode('utf8'))
fp.close()
logger.debug("End RSS Export.")
示例2: Pattern
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import sub [as 别名]
"""
mail.sendMail(to, title, content.decode("utf-8"))
else:
# send web pages to mail Subscriber
logger.info("Begin to send email ...")
pat = Pattern()
db = CrawlDB()
pages = db.getPages()
if pages:
logger.debug("Fetched %s pages." % (len(pages)))
for page in pages:
addrlist = db.getEmailByPid(page["pid"])
if addrlist:
logger.debug("send mail to %s persons..." % (len(addrlist)))
content = pat.sub(page["content"])
if mail.sendMail(addrlist,
page["title"],
content):
db.setUrl(page["url"])
logger.info("Page [%s] is sent to %s\n\n%s\n\n" %
(page["title"], ",".join(addrlist),
content))
else:
logger.info("no mail is sent")
logger.info("End to send email.")
mail.close()
if __name__ == "__main__":