Skip to content

Commit

Permalink
生成中文版PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
tkchu committed Dec 17, 2016
1 parent fecf608 commit 7e57000
Show file tree
Hide file tree
Showing 7 changed files with 4,543 additions and 226 deletions.
795 changes: 795 additions & 0 deletions game-programmer-zh-cn.dot

Large diffs are not rendered by default.

Binary file added game-programmer-zh-cn.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 added game-programmer-zh-cn.pdf
Binary file not shown.
Binary file added game-programmer-zh-cn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,727 changes: 3,727 additions & 0 deletions game-programmer-zh-cn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
204 changes: 0 additions & 204 deletions zh-cn.csv

This file was deleted.

43 changes: 21 additions & 22 deletions zh-cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
import re
import urllib2
import csv
import os

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

def get_image(self, isbn, image_filename):
def get_image(isbn, image_filename):
"""
:type en_isbn: str
:rtype: str
Expand All @@ -30,28 +25,34 @@ def get_image(self, isbn, image_filename):
ft.write(image)

def get_book_url(isbn):
# TODO: 改为从豆瓣上获取真正的URL
return "http://www.douban.com"
url = "https://api.douban.com/v2/book/isbn/" + isbn
response = urllib2.urlopen(url)
detail = response.read()
return json.loads(detail)["alt"]
result = "https://book.douban.com/"
try:
response = urllib2.urlopen(url)
detail = response.read()
return json.loads(detail)["alt"]
except Exception as e:
print isbn
print e
return result

def get_book_info(book_index):
zh = {}
title = "未找到中文"
zh_isbn = ""
with open("isbn.csv") as ff:
spamreader = csv.reader(ff, delimiter=',')
for line in spamreader:
book, en_isbn, zh_title, zh_isbn = line
zh[book] = zh_title.strip()
title = zh[book_index]
if line[0] == book_index:
title = line[2].strip()
zh_isbn = line[3]
if title == "未找到中文":
return None, None
else:
return title, get_book_url(zh_isbn)


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)
LABEL_DICT = {
"":"",
"Recommended Path": "推荐路线",
Expand Down Expand Up @@ -135,8 +136,6 @@ def get_book_info(book_index):
LABEL_LINE = '{label_index} [label="{label}"]\n'
RE_CONTENT_LINE = re.compile(r'[\w ]+\[color="#[\w]{6}", label=[<"]\d+\. [\w ()]+[">]\]')

IMAGE_PATH = './images-zh-cn/{book_index}.jpg'

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 Down

0 comments on commit 7e57000

Please sign in to comment.