Skip to content

Commit

Permalink
v1.20.27
Browse files Browse the repository at this point in the history
邮件中转功能中引入字符串压缩,支持一封邮件内包含更多链接,以便更好的通过发送链接生成电子书。
  • Loading branch information
cdhigh committed Dec 28, 2015
1 parent 47975af commit 0f122c3
Show file tree
Hide file tree
Showing 37 changed files with 1,013 additions and 114 deletions.
1 change: 0 additions & 1 deletion apps/BaseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down
1 change: 0 additions & 1 deletion apps/View/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>
import datetime, urllib
Expand Down
1 change: 0 additions & 1 deletion apps/View/DbViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Deliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
3 changes: 2 additions & 1 deletion apps/View/Login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down Expand Up @@ -128,6 +127,8 @@ def POST(self):

raise web.seeother(r'/my')
else:
import time
time.sleep(5)
tips = _("The username not exist or password is wrong!")
main.session.login = 0
main.session.username = ''
Expand Down
1 change: 0 additions & 1 deletion apps/View/Logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Share.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
1 change: 0 additions & 1 deletion apps/View/Subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Contributors:
# rexdf <https://github.com/rexdf>

Expand Down
8 changes: 5 additions & 3 deletions apps/Work/Url2Book.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
# rexdf <https://github.com/rexdf>

import web
import web, zlib, base64
import jinja2
from apps.BaseHandler import BaseHandler
from apps.dbModels import *
Expand All @@ -33,7 +32,10 @@ def GET(self):
if not all((username,urls,subject,to,language,booktype,tz)):
return "Some parameter missing!<br />"

#global log
if type(urls) is unicode:
urls = urls.encode('utf-8')

urls = zlib.decompress(base64.urlsafe_b64decode(urls))

if booktype == 'Download': #直接下载电子书并推送
from lib.filedownload import Download
Expand Down
5 changes: 3 additions & 2 deletions apps/Work/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down Expand Up @@ -182,7 +181,9 @@ def MergeCovers(self, bks, opts):
book = BookClass(bk.title)
if book and book.coverfile:
coverfiles.append(book.coverfile)

elif DEFAULT_COVER:
coverfiles.append(DEFAULT_COVER)

num_imgs = len(coverfiles)
if num_imgs > 9:#大于9个则随机选择9个
coverfiles = random.sample(coverfiles, 9)
Expand Down
2 changes: 1 addition & 1 deletion apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import __builtin__, sys
from google.appengine.ext import vendor

__Version__ = '1.20.26'
__Version__ = '1.20.27'

__builtin__.__dict__['__Version__'] = __Version__

Expand Down
1 change: 0 additions & 1 deletion apps/dbModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down
22 changes: 12 additions & 10 deletions apps/handlemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
将发到[email protected]的邮件正文转成附件发往管理员的kindle邮箱。
"""
import re
import re, logging, zlib, base64
from email.Header import decode_header
from email.utils import parseaddr, collapse_rfc2231_value
from bs4 import BeautifulSoup
Expand All @@ -18,6 +18,8 @@
from apps.utils import local_time
from config import *

log = logging.getLogger()

def decode_subject(subject):
if subject[0:2] == '=?' and subject[-2:] == '?=':
subject = u''.join(unicode(s, c or 'us-ascii') for s, c in decode_header(subject))
Expand Down Expand Up @@ -62,7 +64,7 @@ def receive(self, message):
and not user.whitelist.filter('mail = ', sender.lower()).get()
and not user.whitelist.filter('mail = ', '@' + mailhost.lower()).get()):
self.response.out.write("Spam mail!")
default_log.warn('Spam mail from : %s' % sender)
log.warn('Spam mail from : %s' % sender)
return

if hasattr(message, 'subject'):
Expand All @@ -80,16 +82,16 @@ def receive(self, message):
try:
allBodies = [body.decode() for ctype, body in html_bodies]
except:
default_log.warn('Decode html bodies of mail failed.')
log.warn('Decode html bodies of mail failed.')
allBodies = []

#此邮件为纯文本邮件
if len(allBodies) == 0:
default_log.info('no html body, use text body.')
log.info('no html body, use text body.')
try:
allBodies = [body.decode() for ctype, body in txt_bodies]
except:
default_log.warn('Decode text bodies of mail failed.')
log.warn('Decode text bodies of mail failed.')
allBodies = []
bodies = u''.join(allBodies)
if not bodies:
Expand Down Expand Up @@ -148,7 +150,7 @@ def receive(self, message):
isbook = link[-4:].lower() in ('.pdf','.txt','.doc','.rtf') if not isbook else isbook

param = {'u':username,
'urls':'|'.join(links),
'urls':base64.urlsafe_b64encode(zlib.compress('|'.join(links), 9)),
'type':'Download' if isbook else user.book_type,
'to':user.kindle_email,
'tz':user.timezone,
Expand Down Expand Up @@ -201,12 +203,12 @@ def receive(self, message):
img['src'] = img['src'][4:]

opts = getOpts()
oeb = CreateOeb(default_log, None, opts)
oeb = CreateOeb(log, None, opts)

setMetaData(oeb, subject[:SUBJECT_WORDCNT_FOR_APMAIL],
user.ownfeeds.language, local_time(tz=user.timezone),
pubtype='book:book:KindleEar')
oeb.container = ServerContainer(default_log)
oeb.container = ServerContainer(log)
id, href = oeb.manifest.generate(id='page', href='page.html')
item = oeb.manifest.add(id, href, 'application/xhtml+xml', data=unicode(soup))
oeb.spine.add(item, False)
Expand All @@ -226,7 +228,7 @@ def receive(self, message):

oIO = byteStringIO()
o = EPUBOutput() if user.book_type == "epub" else MOBIOutput()
o.convert(oeb, oIO, opts, default_log)
o.convert(oeb, oIO, opts, log)
BaseHandler.SendToKindle(username, user.kindle_email,
subject[:SUBJECT_WORDCNT_FOR_APMAIL],
user.book_type, str(oIO.getvalue()), user.timezone)
Expand Down Expand Up @@ -260,7 +262,7 @@ def TrigDeliver(self, subject, username):
if trigbook:
bkids.append(str(trigbook.key().id()))
else:
default_log.warn('book not found : %s' % b.strip())
log.warn('book not found : %s' % b.strip())
if bkids:
taskqueue.add(url='/worker',queue_name="deliverqueue1",method='GET',
params={'u':username,'id':','.join(bkids)},target='worker')
Expand Down
1 change: 0 additions & 1 deletion apps/module_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down
1 change: 0 additions & 1 deletion apps/module_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down
1 change: 0 additions & 1 deletion apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
#A GAE web application to aggregate rss and send it to your kindle.
#Visit https://github.com/cdhigh/KindleEar for the latest version
#中文讨论贴:http://www.hi-pda.com/forum/viewthread.php?tid=1213082
#Author:
# cdhigh <https://github.com/cdhigh>
#Contributors:
Expand Down
4 changes: 2 additions & 2 deletions books/ZhihuDaily.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def ParseFeedUrls(self):
urls.append((section, item['title'], self.url4forwarder(urlfeed), None))
urladded.add(urlfeed)
else:
self.log.warn('fetch rss failed(%d):%s'%(result.status_code, url))
self.log.warn('fetch rss failed(%s):%s' % (URLOpener.CodeMap(result.status_code), url))
return urls

#def fetcharticle(self, url, opener, decoder):
# result = opener.open(self.url4forwarder(url))
# status_code, content = result.status_code, result.content
# if status_code != 200 or not content:
# self.log.warn('fetch article failed(%d):%s.' % (status_code,url))
# self.log.warn('fetch article failed(%s):%s.' % (URLOpener.CodeMap(status_code),url))
# return None
#
# if self.page_encoding:
Expand Down
14 changes: 7 additions & 7 deletions books/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def ParseFeedUrls(self):
urls.append((section, e.title, urlfeed, desc))
urladded.add(urlfeed)
else:
self.log.warn('fetch rss failed(%d):%s'%(result.status_code,url))
self.log.warn('fetch rss failed(%s):%s'%(URLOpener.CodeMap(result.status_code), url))

return urls

Expand Down Expand Up @@ -461,7 +461,7 @@ def fetch(self, url, opener, decoder):
result = opener.open(url)
status_code, content = result.status_code, result.content
if status_code not in (200,206) or not content:
self.log.warn('fetch page failed(%d):%s.' % (status_code,url))
self.log.warn('fetch page failed(%s):%s.' % (URLOpener.CodeMap(status_code), url))
return None

#debug_mail(content)
Expand Down Expand Up @@ -629,7 +629,7 @@ def readability(self, article, url, opts=None, user=None):
else:
img.decompose()
else:
self.log.warn('fetch img failed(err:%d):%s' % (imgresult.status_code,imgurl))
self.log.warn('fetch img failed(%s):%s' % (URLOpener.CodeMap(imgresult.status_code), imgurl))
img.decompose()

#去掉图像上面的链接,以免误触后打开浏览器
Expand Down Expand Up @@ -678,7 +678,7 @@ def readability_by_soup(self, article, url, opts=None, user=None):
try:
title = soup.html.head.title.string
except AttributeError:
self.log.warn('object soup invalid!(%s)'%url)
self.log.warn('object soup invalid!(%s)' % url)
return
if not title:
self.log.warn('article has no title.[%s]' % url)
Expand Down Expand Up @@ -784,7 +784,7 @@ def readability_by_soup(self, article, url, opts=None, user=None):
else:
img.decompose()
else:
self.log.warn('fetch img failed(err:%d):%s' % (imgresult.status_code,imgurl))
self.log.warn('fetch img failed(%s):%s' % (URLOpener.CodeMap(imgresult.status_code), imgurl))
img.decompose()

#去掉图像上面的链接,以免误触后打开浏览器
Expand Down Expand Up @@ -971,7 +971,7 @@ def Items(self, opts=None, user=None):
result = opener.open(url)
status_code, content = result.status_code, result.content
if status_code != 200 or not content:
self.log.warn('fetch article failed(%d):%s.' % (status_code,url))
self.log.warn('fetch article failed(%s):%s.' % (URLOpener.CodeMap(status_code), url))
continue

if self.page_encoding:
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def Items(self, opts=None, user=None):
else:
img.decompose()
else:
self.log.warn('fetch img failed(err:%d):%s' % (imgresult.status_code,imgurl))
self.log.warn('fetch img failed(%s):%s' % (URLOpener.CodeMap(imgresult.status_code), imgurl))
img.decompose()

#去掉图像上面的链接
Expand Down
4 changes: 2 additions & 2 deletions books/weixinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def ParseFeedUrls(self):
else:
content = AutoDecoder(True).decode(result.content,opener.realurl,result.headers)
else:
self.log.warn('fetch rss failed(%d):%s'%(result.status_code,url))
self.log.warn('fetch rss failed(%s):%s' % (URLOpener.CodeMap(result.status_code), url))
continue

eqs, ekv = process_eqs(content)
Expand Down Expand Up @@ -134,6 +134,6 @@ def ParseFeedUrls(self):
urls.append((section, e.title, urlfeed, desc))
urladded.add(urlfeed)
else:
self.log.warn('fetch rss failed(%d):%s'%(result.status_code,url))
self.log.warn('fetch rss failed(%s):%s' % (URLOpener.CodeMap(result.status_code), url))

return urls
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog for KindleEar

##1.20.27
1. 邮件中转功能中引入字符串压缩,支持一封邮件内包含更多链接,以便更好的通过发送链接生成电子书。

##1.20.26
1. 引入html内嵌base64图像技术,减小http请求数量,提升网页加速效率。

Expand Down
3 changes: 3 additions & 0 deletions changelog_en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog for KindleEar

##1.20.27
1. An single email of appspotmail supports more links.

##1.20.26
1. Improve performance of loading webpage via inline base64 image technology.

Expand Down
Binary file modified i18n/tr-tr/LC_MESSAGES/lang.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion i18n/tr-tr/LC_MESSAGES/lang.po
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ msgstr "açık kaynak KindleEar uygulaması"

msgid ""
", You can deploy your own server to push news feeds to your kindle dialy or "
"share with your friends."
"share the service with your friends."
msgstr ""
"ile siz de kendi serverınızı kurup Kindle'ınıza RSS'leri günlük gönderebilir "
"veya arkadaşlarınızla paylaşabilirsiniz."
Expand Down
Binary file modified i18n/zh-cn/LC_MESSAGES/lang.mo
Binary file not shown.
Loading

0 comments on commit 0f122c3

Please sign in to comment.