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
评论列表
文章目录