当前位置: 首页>>代码示例>>Python>>正文


Python Post.load_from_file方法代码示例

本文整理汇总了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
开发者ID:luoluo,项目名称:luoluo.github.com,代码行数:10,代码来源:resources.py

示例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
开发者ID:luoluo,项目名称:luoluo.github.com,代码行数:64,代码来源:resources.py


注:本文中的post.Post.load_from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。