Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1178254
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: Python/Ruby

2014-08-08 22:20:39


  1. # catalog conversion tool
  2. # -- coding: UTF-8 --
  3. # 将一般格式的图书目录转换成pdf文件目录
  4. import sys, os, re;

  5. if len(sys.argv)<3:
  6.     print('Usage: python catalog_conversion.py oldBookCatalog.txt newPdfCatalog.txt [addPageNum]');
  7.     sys.exit(0);

  8. filename = sys.argv[1];
  9. newfilename = sys.argv[2];
  10. if len(sys.argv)==4:
  11.     addPageNum = int(sys.argv[3]);
  12. else:
  13.     addPageNum = 0;

  14. newfd = os.open(newfilename, os.O_WRONLY|os.O_CREAT|os.O_TRUNC);

  15. for line in open(filename):
  16.     if line.isspace(): continue;
  17.     m = re.match('([\s\S]+)\s+(\d+)$', line);
  18.     if not m:
  19.         newline = line.strip()+'/0,Black,notBold,notItalic,open,TopLeftZoom,0,0,0.0'+"\n";
  20.     else:
  21.         newline = m.group(1).strip() + '/' + str(int(m.group(2))+addPageNum) + ',Black,notBold,notItalic,open,TopLeftZoom,0,0,0.0'+"\n";
  22.     try:
  23.         os.write(newfd, newline.encode('GBK'));
  24.     except:
  25.         os.write(newfd, newline);


阅读(650) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~