用于Python的ENML到纯文本转换器

时间:2016-02-05 21:26:53

标签: python django evernote

来自javascript(enml.js)的端口enml库

evernote-sdk-js的ENML.PlainTextOfENML对我有用 我想为Python找到一个很好的这个工具端口。

我尝试使用这些库,但出现了错误:

https://github.com/CarlLee/ENML_PY
ImportError:没有名为bs4的模块

https://github.com/wanasit/enml-py
2013年2月,没有文件,
ImportError:没有名为internals的模块

例如
我想得到:

any sort of liquid damage to an Apple product will void your warranty.

来自

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>any sort of liquid damage to an Apple product will void your warranty.</en-note>

我想要使用enml的代码部分:
views.py

title_contents = {}
for note in result_list.notes:
    content = note_store.getNoteContent(auth_token, 
                                        note_store.getNote(note.guid, 
                                        True,False, False, False).guid)
    title_contents[note.title] = content

enter code herereturn render_to_response('oauth/callback.html', {'notebooks': notebooks, 
                                                  'result_list': result_list, 
                                                  'title_contents': title_contents})

callback.html

    .....
    <ul>
      {% for title, content in title_contents.items %}
        <li><b>{{ title }}</b><br>{{ content }}</li>
      {% endfor %}
    </ul>

1 个答案:

答案 0 :(得分:0)

这种组合可以完成所有需要的事情:

from fenml import ENMLToHTML
# the fenml.py is my internal fork of the 
# https://github.com/CarlLee/ENML_PY/blob/master/__init__.py 
# with slightly modified code. 
from bs4 import BeautifulSoup
import html2text
....
title_contents[note.title] = html2text.html2text(BeautifulSoup(ENMLToHTML(content)).prettify())