diff --git a/common.py b/common.py index 6c3b7eb..009f10e 100644 --- a/common.py +++ b/common.py @@ -14,14 +14,10 @@ from email.parser import BytesParser, Parser from email.policy import default -from bs4 import BeautifulSoup - -from markdown2 import Markdown from datetime import datetime -from pytz import timezone -from html2txt import converters + import hashlib @@ -119,6 +115,7 @@ def create_message_id(id_=None): return ("<%s>@mail.gmail.com" % (id_,)) def text_to_markdown(data): + from markdown2 import Markdown pattern = ( r'((([A-Za-z]{3,9}:(?:\/\/)?)' # scheme r'(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+(:\[0-9]+)?' # user@hostname:port @@ -135,10 +132,13 @@ def text_to_markdown(data): return html_to_markdown(html) def markdown_to_html(data): + from markdown2 import Markdown markdown=Markdown() return markdown.convert(data) def markdown_to_text(data): + from markdown2 import Markdown + from bs4 import BeautifulSoup markdown=Markdown() html = markdown.convert(data) soup = BeautifulSoup(html, "html.parser") @@ -146,11 +146,13 @@ def markdown_to_text(data): return plain_text def html_to_text(data, separator='\n'): + from bs4 import BeautifulSoup soup = BeautifulSoup(data, "html.parser") text = soup.get_text(separator) return text def html_to_markdown(data): + from html2txt import converters markdown = converters.Html2Markdown().convert(data) return markdown diff --git a/notes2html.py b/notes2html.py index 4c3b8da..d34b21e 100755 --- a/notes2html.py +++ b/notes2html.py @@ -163,7 +163,7 @@ def render_html(note,attachments): tag = ['ul','ul','ol','ul'][pstyle - 100] par = rval while indent > 0: - last = par.getchildren()[-1] + last = list(par)[-1] if last.tag != tag: break par = last @@ -172,8 +172,8 @@ def render_html(note,attachments): par = append(par,E(tag)) indent -= 1 par = append(par,E('li')) - elif pstyle == 4 and rval.getchildren()[-1].tag == 'pre': - par = rval.getchildren()[-1] + elif pstyle == 4 and list(rval)[-1].tag == 'pre': + par = list(rval)[-1] append(par,"\n") else: par = append(rval,E(styles.get(pstyle,'p'))) diff --git a/readnotes.py b/readnotes.py index ade4d00..5fbb63b 100755 --- a/readnotes.py +++ b/readnotes.py @@ -13,7 +13,7 @@ from email.parser import BytesParser, Parser from email.policy import default -from bs4 import BeautifulSoup + from datetime import datetime from datetime import timedelta @@ -27,7 +27,7 @@ import common import urllib -from biplist import * + from notes2html import ReadAttachments, ProcessNoteBodyBlob, DefaultCss, PrintAttachments