Skip to content

Commit 402ebb4

Browse files
committed
为中文书籍加入年份
1 parent 7e57000 commit 402ebb4

File tree

6 files changed

+1489
-1393
lines changed

6 files changed

+1489
-1393
lines changed

game-programmer-zh-cn.dot

Lines changed: 93 additions & 93 deletions
Large diffs are not rendered by default.

game-programmer-zh-cn.jpg

31.8 KB
Loading

game-programmer-zh-cn.pdf

430 Bytes
Binary file not shown.

game-programmer-zh-cn.png

667 KB
Loading

game-programmer-zh-cn.svg

Lines changed: 1385 additions & 1292 deletions
Loading

zh-cn.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def get_image(isbn, image_filename):
2424
image = response.read()
2525
ft.write(image)
2626

27-
def get_book_url(isbn):
27+
def get_book_url_year(isbn):
2828
url = "https://api.douban.com/v2/book/isbn/" + isbn
29-
result = "https://book.douban.com/"
29+
result = "https://book.douban.com/", ""
3030
try:
3131
response = urllib2.urlopen(url)
3232
detail = response.read()
33-
return json.loads(detail)["alt"]
33+
return json.loads(detail)["alt"], json.loads(detail)["pubdate"][:4]
3434
except Exception as e:
3535
print isbn
3636
print e
@@ -46,13 +46,15 @@ def get_book_info(book_index):
4646
title = line[2].strip()
4747
zh_isbn = line[3]
4848
if title == "未找到中文":
49-
return None, None
49+
return None, None, None
5050
else:
5151
image_path = IMAGE_PATH.format(book_index=book_index.strip('"'))
5252

5353
if not os.path.exists(image_path):
5454
get_image(zh_isbn, image_path)
55-
return title, get_book_url(zh_isbn)
55+
book_url, book_year = get_book_url_year(zh_isbn)
56+
return title, book_url, book_year
57+
5658
LABEL_DICT = {
5759
"":"",
5860
"Recommended Path": "推荐路线",
@@ -129,13 +131,14 @@ def get_book_info(book_index):
129131
}
130132

131133
RE_BOOK_LINE = re.compile(r'^\"?\w*\"?\w* \[label=<<TABLE[\S ]* URL="https?:/{2}\w.+"]$')
132-
BOOK_LINE = '{book_index} [label=<<TABLE BORDER="0" CELLSPACING="0"><TR><TD WIDTH="100" HEIGHT="100" FIXEDSIZE="TRUE"><IMG SCALE="TRUE" SRC="{image_path}"/></TD></TR><TR><TD>{book_title}</TD></TR></TABLE>> URL="{url}"]\n'
134+
BOOK_LINE = '{book_index} [label=<<TABLE BORDER="0" CELLSPACING="0"><TR><TD WIDTH="100" HEIGHT="100" FIXEDSIZE="TRUE"><IMG SCALE="TRUE" SRC="{image_path}"/></TD></TR><TR><TD>{book_title}<br/>({book_year})</TD></TR></TABLE>> URL="{url}"]\n'
133135
RE_SECTION_LINE = re.compile(r'^label=<<TABLE BORDER="0" CELLPADDING="10"><TR><TD>\d+\.[\w. ()]*</TD></TR></TABLE>>$')
134136
SECTION_LINE = 'label=<<TABLE BORDER="0" CELLPADDING="10"><TR><TD>{section_title}</TD></TR></TABLE>>\n'
135137
RE_LABEL_LINE = re.compile(r'^\w+ \[label="[\w -=\./\\]*"\]$')
136138
LABEL_LINE = '{label_index} [label="{label}"]\n'
137139
RE_CONTENT_LINE = re.compile(r'[\w ]+\[color="#[\w]{6}", label=[<"]\d+\. [\w ()]+[">]\]')
138140

141+
139142
if __name__ == '__main__':
140143
with open("game-programmer.dot") as en_f, open("game-programmer-zh-cn.dot",'w') as zh_f:
141144
for line in en_f:
@@ -157,12 +160,12 @@ def get_book_info(book_index):
157160

158161
if book_line_match != None:
159162
book_index = line_without_space.split(" ")[0]
160-
book_title, book_url = get_book_info(book_index.strip('"'))
163+
book_title, book_url, book_year = get_book_info(book_index.strip('"'))
161164
if book_title == None or book_url == None:
162165
zh_f.write(line)
163166
else:
164167
image_path = IMAGE_PATH.format(book_index=book_index.strip('"'))
165-
writeline = space_front+ BOOK_LINE.format(book_index=book_index, image_path=image_path, book_title=book_title, url=book_url)
168+
writeline = space_front+ BOOK_LINE.format(book_index=book_index, image_path=image_path, book_title=book_title, book_year=book_year, url=book_url)
166169
zh_f.write(writeline)
167170
elif section_line_match != None:
168171
sectionID = re.search(r'\d+\.', line_without_space).group()

0 commit comments

Comments
 (0)