I converted txt files which include Chinese charactors in utf8 to kindle format. it makes a lot of strange signals which can not read in kindle 3. But I found that html files can be converted with no problem.
So I wrote the code to convert tx2 to html. If it can be integrate to calibre, it will be much convinced.
Quote:
import os
import os.path
import glob
import sys
def txt2html (txtfile, basefilename):
html = "<title>" + basefilename + "</title><html><body>"
outfilename = basefilename + ".html"
fin = open (txtfile, 'r')
for textline in fin:
line = "<p>" + textline + "</p>"
html = html + line
html = html + "</body> </html>"
fout = open(outfilename, "w")
fout.write(html)
fout.close()
if __name__ == "__main__":
sys.argv[1:] = [item for arg in sys.argv[1:] for item in glob.glob(arg)]
for infile in sys.argv[1:]:
basefilename = os.path.splitext(infile)[0]
txt2html(infile, basefilename)
|
the code is very ugly. just show some possibilities.
Best regards,
Ben Luo