-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
executable file
·87 lines (76 loc) · 3.66 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# -*- coding: utf8 -*-
import os, re, time, stat
#basedir = os.path.join('/', 'home', 'f8dy', 'web', 'diveintogreasemonkey.org')
basedir = os.path.dirname(os.path.abspath(__file__))
xmldir = os.path.join(basedir, 'xml')
downloaddir = os.path.join(basedir, 'download', 'book')
version = re.compile('fileversion "(.*?)">').search(open(os.path.join(xmldir, 'version.xml')).read()).group(1)
print('Content-type: text/html; charset=utf-8')
print()
print('''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>深入浅出 Greasemonkey</title>
<link rel="shortcut icon" href="/favicon.ico">
<link rel="stylesheet" href="css/dig.css" type="text/css">
<meta http-equiv="Link" content='<css/modern.css>; type="text/css"; rel=stylesheet, <css/empty.css>; type="text/css"; rel=stylesheet'>
<link rev="made" href="mailto:[email protected]">
<meta name="keywords" content="Firefox, Greasemonkey, Javascript, user script, userscript">
</head>
<body id="diveintogreasemonkey-org">
<div class="z" id="intro">
<div class="sectionInner">
<div class="sectionInner2">
<div class="s">
<h1>深入浅出 Greasemonkey</h1>
<p>教老网络学新把戏</p>
</div>
<div class="s">
<ul>
<li>起始页 · </li>
<li><a href="toc/">目录</a> · </li>
<li><a href="download/">下载</a> · </li>
<li><a href="http://www.greasespot.net/">下载 Greasemonkey</a></li>
</ul>
</div>
</div></div></div>
<div id="main"><div id="mainInner">
<p id="breadcrumb"> </p>
<div class="section">
<h2 class="skip">介绍</h2>
<div class="indexread">
<h3><a class="indexlink" title="深入浅出 Greasemonkey 目录" href="toc/">阅读</a></h3>
<p><cite>深入浅出 Greasemonkey</cite> 是一本介绍用 <a title="Greasemonkey 主页" href="http://greasemonkey.mozdev.org/">Greasemonkey</a> 编程的书。Greasemonkey 是用来定制网页的 Firefox 扩展。免费<a title="深入浅出 Greasemonkey table of contents" href="toc/">在线阅读</a>。</p>
<p>有些疑惑?就从 "<a href="install/what-is-greasemonkey.html">什么是 Greasemonkey?</a>" 开始吧!</p>
</div>
<div class="indexdownload">
<h3><a class="indexlink" title="深入浅出 Greasemonkey 下载页" href="http://diveintogreasemonkey.org/download/">稍后再读</a></h3>
<p><cite>深入浅出 Greasemonkey</cite> 有多种格式可供免费下载。当前版本发布于 ''', end=' ')
print(time.strftime('%B %d, %Y.', time.strptime(version, '%Y-%m-%d')).replace(' 0', ' '), end=' ')
print('''</p>
<ul>''')
htmlfile = os.path.join('download', 'book', 'diveintogreasemonkey-html-' + version + '.zip')
pdffile = os.path.join('download', 'book', 'diveintogreasemonkey-pdf-' + version + '.zip')
try:
htmlsize = ' (' + str(int(os.stat(os.path.join(basedir, htmlfile))[stat.ST_SIZE]) / 1024) + ' KB)'
pdfsize = ' (' + str(int(os.stat(os.path.join(basedir, pdffile))[stat.ST_SIZE]) / 1024) + ' KB)'
except Exception as e:
htmlsize = ''
pdfsize = ''
print('''
<li><a title="下载 HTML 格式''' + htmlsize + '''" href="''' + htmlfile + '''">HTML</a></li>
<li><a title="下载 PDF 格式''' + pdfsize + '''" href="''' + pdffile + '''">PDF</a></li>
<li><a href="download/">更多下载</a></li>
</ul>
</div>
</div>
<hr>
<div class="footer">
<p class="copyright">Copyright © 2005 Mark Pilgrim · <a title="send me feedback about this book" href="mailto:[email protected]">[email protected]</a> · <a href="license/gpl.html" title="GNU 通用公共许可证">使用许可</a></p>
</div>
</div></div>
</body>
</html>
''')