Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkchu zh cn #16

Merged
merged 4 commits into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 95 additions & 95 deletions game-programmer-zh-cn.dot

Large diffs are not rendered by default.

Binary file modified images-zh-cn/csapp3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images-zh-cn/gamecodingcomplete4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images-zh-cn/math3dcpcg3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images-zh-cn/physicsforgamedevelopers2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images-zh-cn/unityinaction.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions isbn.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ learntoprogramwithminecraft,9781593276706, 未找到中文, None
adventuresinminecraft,9781118946916, 零基础学Minecraft编程,9787115398970
3dgpforkids,9781937785444, 未找到中文, None
sicp2,9780262011532, 计算机程序的构造和解释,9787111135104
csapp3,9780134092669, 深入理解计算机系统<br/>(原书第2版),9787111321330
csapp3,9780134092669,深入理解计算机系统<br/>(原书第3版),9787111544937
caaqa5,9780123838728, 计算机体系结构,9787115297655
mos4,9780133591620, 现代操作系统(第3版),9787111255444
clrs3,9780262033848, 算法导论(原书第3版),9787111407010
Expand Down Expand Up @@ -56,7 +56,7 @@ umldistilled3,9780321193681, UML精粹,9787121170492
umluserguide2,9780321267979, UML用户指南,9787115148339
ooadwa3,9780201895513, 面向对象分析与设计,9787121173899
foundationsgedmath,9780985811747, 未找到中文, None
math3dcpcg3,9781568817231, 3D数学基础,9787302109464
math3dcpcg3,9781568817231,3D游戏与计算机图形学<br/>中的数学方法(第3版),9787302406228
3dmathprimer2,9781435458864, 未找到中文, None
essentialmaths3,9781482250923, 未找到中文, None
geometricalgebra,9780123694652, 未找到中文, None
Expand All @@ -65,9 +65,9 @@ computationalgeometry,9783540779735, 计算几何,9787302199380
visualizingquaternions,9780120884001, 未找到中文, None
divgradcurl4,9780393925166, 散度、旋度、梯度释义,9787111501718
windowsgp2,9780672323690, Windows游戏编程大师技巧,9787115292483
gamecodingcomplete4,9781133776574, 游戏编程全接触,9787115132192
gamecodingcomplete4,9781133776574,游戏编程权威指南,9787115410344
introtogdprodev,9780321933164, 未找到中文, None
unityinaction,9781617292323, 未找到中文, None
unityinaction,9781617292323,Unity5实战,9787302436744
learninguegd,1784398152, 未找到中文, None
blueprintsvisualscripting,1785286013, 未找到中文, None
cocos2dxbyexample2,9781785288852, 未找到中文, None
Expand Down Expand Up @@ -169,7 +169,7 @@ gameik,1484922328, 未找到中文, None
physicsbasedanimation,9781584503804, 未找到中文, None
rtcameras,9780123116345, 未找到中文, None
physicsforgameprogrammers,9781590594728, 未找到中文, None
physicsforgamedevelopers2,9781449392512, 未找到中文, None
physicsforgamedevelopers2,9781449392512,游戏开发物理学 第2版,9787115384706
physicsmodeling,9781592000937, 未找到中文, None
gamephysicsenginedev2,9780123819765, 游戏物理引擎开发,9787302344568
gamephysics2,9780123749031, 未找到中文, None
Expand Down
21 changes: 12 additions & 9 deletions zh-cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def get_image(isbn, image_filename):
image = response.read()
ft.write(image)

def get_book_url(isbn):
def get_book_url_year(isbn):
url = "https://api.douban.com/v2/book/isbn/" + isbn
result = "https://book.douban.com/"
result = "https://book.douban.com/", ""
try:
response = urllib2.urlopen(url)
detail = response.read()
return json.loads(detail)["alt"]
return json.loads(detail)["alt"], json.loads(detail)["pubdate"][:4]
except Exception as e:
print isbn
print e
Expand All @@ -46,13 +46,15 @@ def get_book_info(book_index):
title = line[2].strip()
zh_isbn = line[3]
if title == "未找到中文":
return None, None
return None, None, None
else:
image_path = IMAGE_PATH.format(book_index=book_index.strip('"'))

if not os.path.exists(image_path):
get_image(zh_isbn, image_path)
return title, get_book_url(zh_isbn)
book_url, book_year = get_book_url_year(zh_isbn)
return title, book_url, book_year

LABEL_DICT = {
"":"",
"Recommended Path": "推荐路线",
Expand Down Expand Up @@ -129,13 +131,14 @@ def get_book_info(book_index):
}

RE_BOOK_LINE = re.compile(r'^\"?\w*\"?\w* \[label=<<TABLE[\S ]* URL="https?:/{2}\w.+"]$')
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'
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'
RE_SECTION_LINE = re.compile(r'^label=<<TABLE BORDER="0" CELLPADDING="10"><TR><TD>\d+\.[\w. ()]*</TD></TR></TABLE>>$')
SECTION_LINE = 'label=<<TABLE BORDER="0" CELLPADDING="10"><TR><TD>{section_title}</TD></TR></TABLE>>\n'
RE_LABEL_LINE = re.compile(r'^\w+ \[label="[\w -=\./\\]*"\]$')
LABEL_LINE = '{label_index} [label="{label}"]\n'
RE_CONTENT_LINE = re.compile(r'[\w ]+\[color="#[\w]{6}", label=[<"]\d+\. [\w ()]+[">]\]')


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

if book_line_match != None:
book_index = line_without_space.split(" ")[0]
book_title, book_url = get_book_info(book_index.strip('"'))
if book_title == None or book_url == None:
book_title, book_url, book_year = get_book_info(book_index.strip('"'))
if book_title == None:
zh_f.write(line)
else:
image_path = IMAGE_PATH.format(book_index=book_index.strip('"'))
writeline = space_front+ BOOK_LINE.format(book_index=book_index, image_path=image_path, book_title=book_title, url=book_url)
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)
zh_f.write(writeline)
elif section_line_match != None:
sectionID = re.search(r'\d+\.', line_without_space).group()
Expand Down