本文整理汇总了Python中post.Post.write方法的典型用法代码示例。如果您正苦于以下问题:Python Post.write方法的具体用法?Python Post.write怎么用?Python Post.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_site
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import write [as 别名]
def update_site(self):
"""Updates only the static pages"""
files = os.listdir(self.datadir)
for f in files:
if f[0] != '.': # leave out hidden files
post = Post(self.datadir+f)
post.write(self.posts, self.tags)
示例2: main
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import write [as 别名]
def main():
try:
opts, args = getopt.getopt(
sys.argv[1:], "ht:d:s:p:", ["title", "help", "publish="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
sys.exit()
elif opt in ('-p', '--publish'):
p = Post(arg)
p.write()
print('Post/page published, you might want to update now.')
elif opt in ('-t', '--title'):
# one-time modification of the template
f = codecs.open(templatedir+'base.html', 'r', encoding)
soup = BeautifulSoup(f.read(), 'html.parser')
f.close()
tag = soup.find('title')
tag.contents[0].replaceWith(arg + '${self.title()}')
tag = soup.find('a', 'title')
tag.contents[0].replaceWith(arg)
f = codecs.open(templatedir+'base.html', 'w', encoding)
f.write(str(soup).decode(encoding))
f.close()
print('Title was set to:' + arg)
sys.exit()
else:
assert False, "unhandled option"
blog = Blog()
for a in args:
if a == 'index':
blog.index()
elif a == 'archive':
blog.archive()
if args == []:
if site_type == 'blog':
print("--> Updating your blog")
blog.update_blog()
else:
print("--> Updating your site")
blog.update_site()
示例3: InitializationTestCase
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import write [as 别名]
class InitializationTestCase(unittest.TestCase):
def setUp(self):
self.datadir = "testdata/"
self.sitedir = "testsite/"
os.mkdir(self.datadir)
os.mkdir(self.sitedir)
os.mkdir(self.sitedir + config.postdir)
f = open(self.datadir + "01-01-01-10:00-post", "w", encoding=config.encoding)
f.write("name\n---\n\nh1. foo bar baz bâș\n")
f.close()
self.post = Post(self.datadir + "01-01-01-10:00-post", sitedir=self.sitedir)
self.post.write([self.post], [])
self.blog = Blog(self.datadir, self.sitedir)
self.template = Template("TEST: ${posts[0].body}", default_filters=["decode.utf8"])
def tearDown(self):
os.remove(self.datadir + "01-01-01-10:00-post")
os.remove(self.sitedir + config.postdir + "post.html")
os.rmdir(self.sitedir + config.postdir)
os.rmdir(self.datadir)
os.rmdir(self.sitedir)