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

问题描述 投票:2回答:1

来自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>
python django evernote
1个回答
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())
© www.soinside.com 2019 - 2024. All rights reserved.