util.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:henet 作者: AcrDijon 项目源码 文件源码
def parse_article(path, cache_dir, root_path):
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)

    # XXX two reads...
    with open(path) as f:
        file_md5 = md5(f.read())

    cache = os.path.join(cache_dir, file_md5)

    if os.path.exists(cache):
        with open(cache) as f:
            article = Article(bson.loads(f.read()))
    else:
        article = parse(path)
        article['filename'] = path[len(root_path):].lstrip('/')
        with open(cache, 'w') as f:
            f.write(bson.dumps(article))

    return article
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号