Skip to content

mfs6174/Readablity6174

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mfs6174's readability service on GAE

GAE application which can convert a webpage (url provided through http GET) to clean,readable article PDF file (contains original format and images) . Chinese webpages (UTF-8 or GBK coded) are supported. This project is based on Readability (https://github.com/kingwkb/readability)  and xhtml2pdf(http://www.xhtml2pdf.com). 

usage
1.clone
2.change fontName fontFile in main.py and put the fontfile in fonts folder if you like. Set sendMail in main.py to True and set mailFrom mailTo in mainTask.py if you want to sent mail with pdf attachment.
3.set userKey in main.py and appid in app.yaml
4.upload to google app engine(GAE)
5.GET http(s)://your-appid.appspot.com/trans?key=your-userkey&clean=1&pdf=1&url=your-url


移植Readability和xhtml2pdf至GAE并加入中文支持过程中遇到的主要问题

1.Readability使用beautifulSoup解析html时对一些非标准的字符的标签(<!--)不能识别,使用一个replace('\xe2\x80\x93','--')来解决

2.中文字体的支持,在html数据的头部添加一个@fontface的CSS指定字体,并且字体要放在一个app.yaml定义的static之外的目录中,否则不能使用(参考https://groups.google.com/forum/#!msg/xhtml2pdf/U5HeC36CPSQ/u_py6zD7JGoJ),并且只有部分字体被支持

3.中文不能换行,超过pdf页面显示范围.使用了来自http://slee.sinaapp.com/?p=76 的代码来解决

4.xhtml2pdf使用的reportlab需要python image library(PIL)来把非jpg的图片加入pdf,但是PIL不是纯python库,不能运行在GAE上,而PNG和gif也是常见的网络图片.我修改了xhtml2pdf中的xhtml2pdf_reportlab.py,使用GAE api的images将各种格式的图片转换为jpg,再交给reportlab处理

5.GAE上运行处理html和图片太容易超时,加了个用taskQueue发邮件(pdf附件)的功能来保证一定能可靠得到pdf.






About

mfs6174's readability service on GAE

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages