本文整理汇总了Python中post.Post.load_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Post.load_from_file方法的具体用法?Python Post.load_from_file怎么用?Python Post.load_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.load_from_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_post
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load_from_file [as 别名]
def load_post(self):
""" load post
"""
for post_source in glob.glob(self.post_path + self.post_pattern):
post = Post()
post.load_from_file(post_source)
# self.posts.append(post)
self.post_mapping[post.link] = post
示例2: Resources
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load_from_file [as 别名]
class Resources(object):
""" resource
"""
def __init__(self, post_path="./_post/"):
self.post_path = post_path
self.post_pattern = "*markdown"
self.post_mapping = {}
self.categories_mapping = collections.defaultdict(list)
self.notes = None
self.about = None
def load_post(self):
""" load post
"""
for post_source in glob.glob(self.post_path + self.post_pattern):
post = Post()
post.load_from_file(post_source)
# self.posts.append(post)
self.post_mapping[post.link] = post
def load_note(self):
""" load note
"""
self.notes = Post()
self.notes.load_from_file(self.post_path + "note/note.markdown")
def load_about(self):
""" load note
"""
self.about = Post()
self.about.load_from_file(self.post_path + "about/about.markdown")
def make_categories(self):
for post in self.post_mapping.values():
for category in post.categories:
self.categories_mapping[category].append(post)
def init(self):
self.load_post()
self.load_note()
self.load_about()
self.make_categories()
def get_note(self):
return self.notes
def get_about(self):
return self.about
def get(self, link):
# TODO add debug conf, this should open when writing new article
# self.init()
return self.post_mapping.get(link)
def posts(self):
return sorted(self.post_mapping.values(), key=lambda x: x.date, reverse=True)
def categories(self):
return [(k, v) for k, v in self.categories_mapping.items()]
def static_dump(self):
pass