Skip to content

Commit 7e57000

Browse files
committed
生成中文版PDF
1 parent fecf608 commit 7e57000

File tree

7 files changed

+4543
-226
lines changed

7 files changed

+4543
-226
lines changed

game-programmer-zh-cn.dot

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

game-programmer-zh-cn.jpg

1.46 MB
Loading

game-programmer-zh-cn.pdf

46.8 MB
Binary file not shown.

game-programmer-zh-cn.png

5.11 MB
Loading

game-programmer-zh-cn.svg

Lines changed: 3727 additions & 0 deletions
Loading

zh-cn.csv

Lines changed: 0 additions & 204 deletions
This file was deleted.

zh-cn.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
import re
77
import urllib2
88
import csv
9+
import os
910

10-
def get_isbn_from_douban(douban_url):
11-
isbn = ""
12-
response = urllib2.urlopen(douban_url)
13-
html = response.read()
14-
isbn_url = r"ISBN:</span> \d{10,13}"
15-
isbn = re.search(isbn_url, html).group()[13:]
16-
return isbn
11+
IMAGE_PATH = './images-zh-cn/{book_index}.jpg'
1712

18-
def get_image(self, isbn, image_filename):
13+
def get_image(isbn, image_filename):
1914
"""
2015
:type en_isbn: str
2116
:rtype: str
@@ -30,28 +25,34 @@ def get_image(self, isbn, image_filename):
3025
ft.write(image)
3126

3227
def get_book_url(isbn):
33-
# TODO: 改为从豆瓣上获取真正的URL
34-
return "http://www.douban.com"
3528
url = "https://api.douban.com/v2/book/isbn/" + isbn
36-
response = urllib2.urlopen(url)
37-
detail = response.read()
38-
return json.loads(detail)["alt"]
29+
result = "https://book.douban.com/"
30+
try:
31+
response = urllib2.urlopen(url)
32+
detail = response.read()
33+
return json.loads(detail)["alt"]
34+
except Exception as e:
35+
print isbn
36+
print e
37+
return result
3938

4039
def get_book_info(book_index):
41-
zh = {}
40+
title = "未找到中文"
41+
zh_isbn = ""
4242
with open("isbn.csv") as ff:
4343
spamreader = csv.reader(ff, delimiter=',')
4444
for line in spamreader:
45-
book, en_isbn, zh_title, zh_isbn = line
46-
zh[book] = zh_title.strip()
47-
title = zh[book_index]
45+
if line[0] == book_index:
46+
title = line[2].strip()
47+
zh_isbn = line[3]
4848
if title == "未找到中文":
4949
return None, None
5050
else:
51-
return title, get_book_url(zh_isbn)
52-
53-
51+
image_path = IMAGE_PATH.format(book_index=book_index.strip('"'))
5452

53+
if not os.path.exists(image_path):
54+
get_image(zh_isbn, image_path)
55+
return title, get_book_url(zh_isbn)
5556
LABEL_DICT = {
5657
"":"",
5758
"Recommended Path": "推荐路线",
@@ -135,8 +136,6 @@ def get_book_info(book_index):
135136
LABEL_LINE = '{label_index} [label="{label}"]\n'
136137
RE_CONTENT_LINE = re.compile(r'[\w ]+\[color="#[\w]{6}", label=[<"]\d+\. [\w ()]+[">]\]')
137138

138-
IMAGE_PATH = './images-zh-cn/{book_index}.jpg'
139-
140139
if __name__ == '__main__':
141140
with open("game-programmer.dot") as en_f, open("game-programmer-zh-cn.dot",'w') as zh_f:
142141
for line in en_f:

0 commit comments

Comments
 (0)