Contents
ScrapBook输出重整
问题
常常有人问:
首页怎么生成的...
其实是ScrapBook 人家自个儿的功能哪!
Ctrl+f 打开 ScrapBook 侧栏->工具->导出项目列表 选择"连帧输出"
- 只是有个小问题:
- 默认输出的 index.html 是索引页面,frame.html 才是帧结构页
- 想同步发布到网站中,就得转换一下:
- 将 index.html 复制成 idx.html
- 将 frame.html 复制成 index.html
- 修订 frame.html 对应将 idx.html 定义成包含的页面
所以,写了个脚本来自动修订...
fixhtmlexp.py
Toggle line numbers
1 # coding : utf-8
2
3 import sys,os,string,stat
4 import time,datetime
5 __version__="fixhtmlexp.py 0.9.1"
6
7 class fixhtmlexp:
8 """main class zip all done
9 """
10 def __init__(self):
11 """ini all
12 """
13 self.dirbook = sys.argv[1]
14 self.dirtree = "tree/"
15 self.tree = "frame.html"
16 self.index = "index.html"
17 self.idx = "idx.html"
18 self.daylog = "%s"%(time.strftime("%y%m%d %H:%M:%S",time.localtime()))
19
20 def idxit(self):
21 """re index the tree of ScrapBook:
22 - replace src="./index.html" as src="./idx.html" in frame.html
23 - if replaced ,cancel flow ..! judge by SIZE of index.html
24 - cp index.html as idx.html
25 - cp frame.html as index.html
26 """
27 root = self.dirbook+self.dirtree
28 oldframe = open(root+self.tree).read()
29 print "%s ST_SIZE::%s"%((root+self.index),os.stat(root+self.index)[stat.ST_SIZE])
30 if 800 < os.stat(root+self.index)[stat.ST_SIZE]:
31 # not replace yet
32 newframe = string.replace(oldframe,"index.html","idx.html")
33 open(root+self.idx,"w").write(open(root+self.index).read())
34 open(root+self.index,"w").write(newframe)
35 else:
36 print "replaced! do nothing..."
37
38 def title(self):
39 """readt scrpabook export index.html:
40 - fixed Title for zoomquiet.org
41 """
42 expname = self.dirbook.split("/")[1]
43 orgiIdx = open(self.dirbook+self.dirtree+self.index)
44 mark = "<title>"
45 retit = ""
46 for line in orgiIdx:
47 if mark in line:
48 #print line
49 if "</title>" not in line:
50 retit += line
51 else:
52 print line
53 newTit='''
54 <title>%s in zoomquiet.org
55 reformat by %s
56 {%s}-ScrapBook</title>
57 '''%(expname,__version__,self.daylog)
58 print newTit
59 retit += newTit
60 else:
61 retit += line
62 orgiIdx.close()
63 open(self.dirbook+self.dirtree+self.index,"w").write(retit)
64
65
66 if __name__ == '__main__':
67 fix = fixhtmlexp()
68 fix.idxit()
69 print ":::And fixed title"
70 fix.title()
使用
# 将脚本部属在任何目录中 $ python fixhtmlexp.py /path/2/my/scrapbook/ # 指定要处理哪个 ScrapBook 本地目录中的导出含帖索引页面, # 一般目录下的文件结构是: +-- backup +-- data +-- GDscratchPad +-- icon +-- tree |-- blockcomment.css |-- folders.txt |-- note.html |-- note_template.html `-- scrapbook.rdf
反馈
创建 by -- ZoomQuiet [2010-09-16 09:21:02]