# catalog conversion tool
# -- coding: UTF-8 --
# 将一般格式的图书目录转换成pdf文件目录
import sys, os, re;
if len(sys.argv)<3:
print('Usage: python catalog_conversion.py oldBookCatalog.txt newPdfCatalog.txt [addPageNum]');
sys.exit(0);
filename = sys.argv[1];
newfilename = sys.argv[2];
if len(sys.argv)==4:
addPageNum = int(sys.argv[3]);
else:
addPageNum = 0;
newfd = os.open(newfilename, os.O_WRONLY|os.O_CREAT|os.O_TRUNC);
for line in open(filename):
if line.isspace(): continue;
m = re.match('([\s\S]+)\s+(\d+)$', line);
if not m:
newline = line.strip()+'/0,Black,notBold,notItalic,open,TopLeftZoom,0,0,0.0'+"\n";
else:
newline = m.group(1).strip() + '/' + str(int(m.group(2))+addPageNum) + ',Black,notBold,notItalic,open,TopLeftZoom,0,0,0.0'+"\n";
try:
os.write(newfd, newline.encode('GBK'));
except:
os.write(newfd, newline);
[python]将一般格式的图书目录转换成pdf文件目录
最新推荐文章于 2023-11-30 09:44:49 发布