rimport.py 文件源码

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

项目:rvo 作者: noqqe 项目源码 文件源码
def import_mail(ctx, tag, category):
    content = ""
    for l in click.get_text_stream('stdin'):
        content = content + l
    msg = email.message_from_string(content)

    # title
    subject, encoding = email.header.decode_header(msg['Subject'])[0]
    if encoding is None:
        encoding = "utf-8"

    title = subject.decode(encoding)

    # content
    content = msg.get_payload(decode=False)
    content = quopri.decodestring(content)
    content = "# " + title + '\n\n' + content
    date = datetime.datetime.now()

    coll = db.get_document_collection(ctx)
    config = ctx.obj["config"]

    item = {
        "title": title,
        "content": content,
        "tags": list(tag),
        "categories": list(category),
        "created": date,
        "updated": date,
        "encrypted": False,
    }

    # insert item if its valid
    if validate(item):
        coll = db.get_document_collection(ctx)
        docid = coll.insert_one(item).inserted_id

        transaction.log(ctx, str(docid), "import", title)
        utils.log_info("Document \"%s\" created." % title)

    else:
        utils.log_error("Validation of the updated object did not succeed")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号