main.py 文件源码

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

项目:easyblogger 作者: raghur 项目源码 文件源码
def printPosts(item, fields, docFormat=None, writeToFiles=False):
    template = """+++
{0}
+++

{1}
"""
    logger.debug(json.dumps(item,
                            sort_keys=True,
                            indent=2,
                            separators=(',', ': ')))
    if docFormat:
        logger.debug("Starting to print %s", item['id'])
        filename = None
        content = item["content"].encode('utf-8', "ignore")
        if writeToFiles:
            filename = getFilenameFromPostUrl(item['url'], docFormat)
            with open(filename, "wb") as outputFile:
                outputFile.write(content)
            converted = pypandoc.convert_file(
                filename,
                docFormat,
                format="html")
            content = template.format(getFrontMatter(item),
                                      converted).encode('utf-8',
                                                        'ignore')
            with open(filename, "wb") as outputfile:
                outputfile.write(content)
        else:
            print(content)
        logger.info("Finished print %s: %s", item['id'], filename)
    elif isinstance(fields, basestring):
        fields = fields.split(",")
        line = [str(item[k]) for k in fields if k in item]
        print(",".join(line))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号