在Python中将字符串连接到 Evernote标记语言(ENML)

2024-04-29 01:39:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望添加一个字符串包含用户的文本输入到注释.内容我注意到了。在阅读之后,我发现了如何添加资源,但我不希望资源是附件,我希望它是实际的文本。在

下面是一些代码:

    title= self.textEditTitle.text()
    body= self.textEditBody.text()        

    auth_token = "secret stuff!"

    client = EvernoteClient(token=auth_token, sandbox=True)

    note_store = client.get_note_store()

    nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
    nBody += "<en-note>%s</en-note>" % body

    note = Types.Note()
    note.title = title
    note.content= nBody

任何建议都会很好,因为我刚刚开始使用这个api,而且一旦我发现它,它看起来充满了潜力!以下是我一直在读的内容:http://dev.evernote.com/documentation/cloud/chapters/ENML.php


Tags: storetext文本selfclienttokenauth内容
1条回答
网友
1楼 · 发布于 2024-04-29 01:39:20

找到了答案。首先,我使用的是QString对象,而不是普通的string对象。我将QString转换为一个字符串,并将内容分隔开,因此我将body变量本身连接起来。我还将字符串编码到xmlcharrefreplace中,但我仍在阅读。尽管如此,它还是有效的。以下是代码剪辑:

    body= str(self.textEditBody.text())
    auth_token = "secret!"
    client = EvernoteClient(token=auth_token, sandbox=True)
    note_store = client.get_note_store()

    nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
    nBody += "<en-note>"
    nBody += body.encode('ascii', 'xmlcharrefreplace')
    nBody += "</en-note>"

相关问题 更多 >