Skip to content

Commit

Permalink
1.25
Browse files Browse the repository at this point in the history
1. 添加漫画模式和多本漫画书。
 2. 添加对Kindle Voyage和Kindle PaperWhite3的支持。
  • Loading branch information
chsqyuan committed Sep 7, 2017
1 parent f935769 commit 4b6936e
Show file tree
Hide file tree
Showing 144 changed files with 17,502 additions and 6,037 deletions.
8 changes: 4 additions & 4 deletions apps/View/DbViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def GET(self):
#可以修改UrlEncoding,如果chardet自动检测的编码错误的话
action = web.input().get('action')
if action == 'modurlenc':
id = int(web.input().get('id', 0))
id_ = int(web.input().get('id', 0))
feedenc = web.input().get('feedenc')
pageenc = web.input().get('pageenc')
urlenc = UrlEncoding.get_by_id(id)
urlenc = UrlEncoding.get_by_id(id_)
if urlenc:
if feedenc: urlenc.feedenc = feedenc
if pageenc: urlenc.pageenc = pageenc
urlenc.put()
elif action == 'delurlenc':
id = int(web.input().get('id', 0))
urlenc = UrlEncoding.get_by_id(id)
id_ = int(web.input().get('id', 0))
urlenc = UrlEncoding.get_by_id(id_)
if urlenc:
urlenc.delete()
return self.render('dbviewer.html', "DbViewer",
Expand Down
14 changes: 7 additions & 7 deletions apps/View/Deliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def queueit(self, usr, bookid, separate):
param = {"u":usr.name, "id":bookid}

if usr.merge_books and not separate:
self.queue2push[usr.name].append(str(bookid))
self.queue2push[usr.name].append(str(bookid)) #合并推送
else:
taskqueue.add(url='/worker',queue_name="deliverqueue1",method='GET',
params=param,target="worker")
taskqueue.add(url='/worker', queue_name="deliverqueue1", method='GET',
params=param, target="worker")

def flushqueue(self):
for name in self.queue2push:
Expand All @@ -38,17 +38,17 @@ def flushqueue(self):

def GET(self):
username = web.input().get('u')
id = web.input().get('id') #for debug
id_ = web.input().get('id') #for debug

self.queue2push = defaultdict(list)

books = Book.all()
if username: #现在投递,不判断时间和星期
if username: #现在投递【测试使用】,不需要判断时间和星期
sent = []
books2push = Book.get_by_id(int(id)) if id and id.isdigit() else None
books2push = Book.get_by_id(int(id_)) if id_ and id_.isdigit() else None
books2push = [books2push] if books2push else books
for book in books2push:
if not id and username not in book.users:
if not id_ and username not in book.users:
continue
user = KeUser.all().filter("name = ", username).get()
if user and user.kindle_email:
Expand Down
79 changes: 76 additions & 3 deletions apps/View/Logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from apps.dbModels import *
from apps.utils import etagged
from google.appengine.api.datastore_errors import NeedIndexError
import web
try:
import json
except ImportError:
import simplejson as json

class Mylogs(BaseHandler):
__url__ = "/logs"
Expand All @@ -20,6 +25,8 @@ def GET(self):
mylogs = DeliverLog.all().filter("username = ", user.name).order('-time').fetch(limit=10)
except NeedIndexError: #很多人不会部署,经常出现没有建立索引的情况,干脆碰到这种情况直接消耗CPU时间自己排序得了
mylogs = sorted(DeliverLog.all().filter("username = ", user.name), key=attrgetter('time'), reverse=True)[:10]

#其他用户的推送记录
logs = {}
if user.name == 'admin':
for u in KeUser.all().filter("name != ", 'admin'):
Expand All @@ -29,9 +36,26 @@ def GET(self):
ul = sorted(DeliverLog.all().filter("username = ", user.name), key=attrgetter('time'), reverse=True)[:5]
if ul:
logs[u.name] = ul

#管理员可以查看所有用户的已推送期号,其他用户只能查看自己的已推送期号
if user.name == 'admin':
try:
lastDelivered = LastDelivered.all().order('-datetime').fetch(limit=100)
except NeedIndexError:
lastDelivered = sorted(LastDelivered.all().fetch(), key=attrgetter('datetime'), reverse=True)[:100]
else:
try:
lastDelivered = LastDelivered.all().filter('username = ', user.name).order('-datetime').fetch(limit=100)
except NeedIndexError:
lastDelivered = sorted(LastDelivered.all().filter('username = ', user.name), key=attrgetter('datetime'), reverse=True)[:100]

if len(lastDelivered) == 0:
lastDelivered = None

return self.render('logs.html', "Deliver log", current='logs',
mylogs=mylogs, logs=logs)
mylogs=mylogs, logs=logs, lastDelivered=lastDelivered)

#每天自动运行的任务,清理过期log
class RemoveLogs(BaseHandler):
__url__ = "/removelogs"
def GET(self):
Expand All @@ -41,10 +65,59 @@ def GET(self):
user.enable_send = False
user.put()

#清理30天之前的推送记录
query = DeliverLog.all()
query.filter('datetime < ', datetime.datetime.utcnow() - datetime.timedelta(days=25))
query.filter('datetime < ', datetime.datetime.utcnow() - datetime.timedelta(days=30))
logs = query.fetch(1000)
c = len(logs)
db.delete(logs)

return "%s lines log removed.<br />" % c
#清理过期的已推送期号
query = LastDelivered.all()
query.filter('datetime < ', datetime.datetime.utcnow() - datetime.timedelta(days=90))
logs = query.fetch(1000)
db.delete(logs)

return "%s lines delivery log removed.<br />" % c

#修改/删除已推送期号的AJAX处理函数
class LastDeliveredAjax(BaseHandler):
__url__ = "/lastdelivered/(.*)"

def POST(self, mgrType):
web.header('Content-Type', 'application/json')
user = self.getcurrentuser()

if mgrType.lower() == 'delete':
id_ = web.input().get('id_')
try:
id_ = int(id_)
except:
return json.dumps({'status': _('The id is invalid!')})

dbItem = LastDelivered.get_by_id(id_)
if dbItem:
dbItem.delete()
return json.dumps({'status':'ok'})
else:
return json.dumps({'status': _('The LastDelivered item(%d) not exist!') % id_})
elif mgrType.lower() == 'change':
id_ = web.input().get('id_')
num = web.input().get('num')
try:
id_ = int(id_)
num = int(num)
except:
return json.dumps({'status': _('The id or num is invalid!')})

dbItem = LastDelivered.get_by_id(id_)
if dbItem:
dbItem.num = num
dbItem.record = '' #手工修改了期号则清空文字描述
dbItem.put()
return json.dumps({'status': 'ok', 'num': num})
else:
return json.dumps({'status': _('The LastDelivered item(%d) not exist!') % id_})
else:
return json.dumps({'status': 'unknown command: %s' % mgrType})

36 changes: 19 additions & 17 deletions apps/View/Setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,39 @@ class Setting(BaseHandler):
@etagged()
def GET(self, tips=None):
user = self.getcurrentuser()
return self.render('setting.html',"Setting",
current='setting',user=user,mail_sender=SRC_EMAIL,tips=tips)
return self.render('setting.html', "Setting",
current='setting', user=user, mail_sender=SRC_EMAIL, tips=tips)

def POST(self):
user = self.getcurrentuser()
kemail = web.input().get('kindleemail')
mytitle = web.input().get("rt")
webInput = web.input()
kemail = webInput.get('kindleemail')
mytitle = webInput.get("rt")
if not kemail:
tips = _("Kindle E-mail is requied!")
elif not mytitle:
tips = _("Title is requied!")
else:
user.kindle_email = kemail
user.timezone = int(web.input().get('timezone', TIMEZONE))
user.send_time = int(web.input().get('sendtime'))
user.enable_send = bool(web.input().get('enablesend'))
user.book_type = web.input().get('booktype')
user.device = web.input().get('devicetype') or 'kindle'
user.use_title_in_feed = bool(web.input().get('titlefrom') == 'feed')
user.titlefmt = web.input().get('titlefmt')
user.timezone = int(webInput.get('timezone', TIMEZONE))
user.send_time = int(webInput.get('sendtime'))
user.enable_send = bool(webInput.get('enablesend'))
user.book_type = webInput.get('booktype')
user.device = webInput.get('devicetype') or 'kindle'
user.use_title_in_feed = bool(webInput.get('titlefrom') == 'feed')
user.titlefmt = webInput.get('titlefmt')
alldays = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
user.send_days = [day for day in alldays if web.input().get(day)]
user.merge_books = bool(web.input().get('mergebooks'))
user.send_days = [day for day in alldays if webInput.get(day)]
user.merge_books = bool(webInput.get('mergebooks'))
user.book_mode = webInput.get('bookmode')
user.put()

myfeeds = user.ownfeeds
myfeeds.language = web.input().get("lng")
myfeeds.language = webInput.get("lng")
myfeeds.title = mytitle
myfeeds.keep_image = bool(web.input().get("keepimage"))
myfeeds.oldest_article = int(web.input().get('oldest', 7))
myfeeds.users = [user.name] if web.input().get("enablerss") else []
myfeeds.keep_image = bool(webInput.get("keepimage"))
myfeeds.oldest_article = int(webInput.get('oldest', 7))
myfeeds.users = [user.name] if webInput.get("enablerss") else []
myfeeds.put()
tips = _("Settings Saved!")

Expand Down
2 changes: 1 addition & 1 deletion apps/View/Share.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def SaveToEvernoteWiz(self, user, action, orgUrl):
main.log.warn('No have wiz mail yet.')
return "No have wiz mail yet."

book = BaseUrlBook()
book = BaseUrlBook(user=user)
book.title = book.description = action
book.language = user.ownfeeds.language
book.keep_image = user.ownfeeds.keep_image
Expand Down
58 changes: 37 additions & 21 deletions apps/View/Subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from apps.utils import etagged
from apps.BaseHandler import BaseHandler
from apps.dbModels import *
from books import BookClasses, BookClass
from books.base import BaseComicBook

class MySubscription(BaseHandler):
__url__ = "/my"
Expand Down Expand Up @@ -44,6 +46,7 @@ def POST(self): # 添加自定义RSS
memcache.delete('%d.feedscount'%user.ownfeeds.key().id())
raise web.seeother('/my')

#添加/删除自定义RSS订阅的AJAX处理函数
class FeedsAjax(BaseHandler):
__url__ = "/feeds/(.*)"

Expand Down Expand Up @@ -84,25 +87,28 @@ def POST(self, mgrType):
respDict['feedid'] = fd.key().id()
memcache.delete('%d.feedscount' % user.ownfeeds.key().id())
return json.dumps(respDict)
else:
return json.dumps({'status': 'unknown command: %s' % mgrType})


#订阅/退订内置书籍的AJAX处理函数
class BooksAjax(BaseHandler):
__url__ = "/books/(.*)"

def POST(self, mgrType):
web.header('Content-Type', 'application/json')
user = self.getcurrentuser()
id_ = web.input().get('id_')
try:
id_ = int(id_)
except:
return json.dumps({'status': _('The id is invalid!')})

if mgrType.lower() == 'unsubscribe':
id_ = web.input().get('id_')
try:
id_ = int(id_)
except:
return json.dumps({'status': _('The id is invalid!')})

bk = Book.get_by_id(id_)
if not bk:
return json.dumps({'status': _('The book(%d) not exist!') % id_})
bk = Book.get_by_id(id_)
if not bk:
return json.dumps({'status': _('The book(%d) not exist!') % id_})

if mgrType.lower() == 'unsubscribe':
if user.name in bk.users:
bk.users.remove(user.name)
bk.separate = False
Expand All @@ -115,23 +121,21 @@ def POST(self, mgrType):

return json.dumps({'status':'ok', 'title': bk.title, 'desc': bk.description})
elif mgrType.lower() == 'subscribe':
id_ = web.input().get('id_')
separate = web.input().get('separate', '')

respDict = {'status':'ok'}

try:
id_ = int(id_)
except:
return json.dumps({'status': _('The id is invalid')})

bk = Book.get_by_id(id_)
if not bk:
bkcls = BookClass(bk.title)
if not bkcls:
return json.dumps({'status': 'The book(%d) not exist!' % id_})

#如果是漫画类,则不管是否选择了“单独推送”,都自动变成“单独推送”
if issubclass(bkcls, BaseComicBook):
separate = 'true'

if user.name not in bk.users:
bk.users.append(user.name)
bk.separate = bool(separate.lower() in ('true','1'))
bk.separate = bool(separate.lower() in ('true', '1'))
bk.put()

respDict['title'] = bk.title
Expand All @@ -140,7 +144,9 @@ def POST(self, mgrType):
respDict['subscription_info'] = bool(user.subscription_info(bk.title))
respDict['separate'] = bk.separate
return json.dumps(respDict)

else:
return json.dumps({'status': 'unknown command: %s' % mgrType})

class Subscribe(BaseHandler):
__url__ = "/subscribe/(.*)"
def GET(self, id_):
Expand All @@ -154,9 +160,19 @@ def GET(self, id_):
if not bk:
return "the book(%d) not exist!<br />" % id_

bkcls = BookClass(bk.title)
if not bkcls:
return "the book(%d) not exist!<br />" % id_

#如果是漫画类,则不管是否选择了“单独推送”,都自动变成“单独推送”
if issubclass(bkcls, BaseComicBook):
separate = 'true'
else:
separate = web.input().get('separate', 'true')

if main.session.username not in bk.users:
bk.users.append(main.session.username)
bk.separate = bool(web.input().get('separate') in ('true','1'))
bk.separate = bool(separate in ('true', '1'))
bk.put()
raise web.seeother('/my')

Expand Down
41 changes: 0 additions & 41 deletions apps/View/UpdateLogs.py

This file was deleted.

Loading

0 comments on commit 4b6936e

Please sign in to comment.