rewrite with python3

This commit is contained in:
Yuxin Wu
2020-06-27 15:21:17 -07:00
parent 503a43c953
commit 95826392df
23 changed files with 173 additions and 225 deletions
+8 -7
View File
@@ -1,17 +1,17 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# File: dump-html.py
# Date: Wed Mar 25 17:44:20 2015 +0800
# Author: Yuxin Wu
import sys
import argparse
import logging
from common.textutil import ensure_unicode
from wechat.parser import WeChatDBParser
from wechat.res import Resource
from wechat.render import HTMLRender
logger = logging.getLogger("wechat")
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('name', help='name of contact')
@@ -39,7 +39,7 @@ if __name__ == '__main__':
sys.exit(1)
res = Resource(parser, args.res, args.avt)
msgs = parser.msgs_by_chat[chatid]
print "Number of Messages: ", len(msgs)
logger.info(f"Number of Messages: {len(msgs)}")
assert len(msgs) > 0
render = HTMLRender(parser, res)
@@ -47,10 +47,11 @@ if __name__ == '__main__':
if len(htmls) == 1:
with open(output_file, 'w') as f:
print >> f, htmls[0].encode('utf-8')
f.write(htmls[0])
else:
assert output_file.endswith(".html")
basename = output_file[:-5]
for idx, html in enumerate(htmls):
with open(basename + '.{}'.format(idx) + '.html', 'w') as f:
print >> f, html.encode('utf-8')
f.write(html)
res.emoji_cache.flush()