Exemplo n.º 1
0
    def AddBookEpsInfoBack(self, backData):
        # 此处在线程中加载后续章节 TODO 章节太多时会导致太慢
        try:
            r = backData.res
            bookId = backData.req.bookId
            info = self.books.get(bookId)
            info.epsCount = r.data['eps']["total"]
            page = r.data['eps']["page"]

            # 重新初始化
            pages = r.data['eps']["pages"]
            limit = r.data['eps']["limit"]
            # 优化,如果分页已经加载好了,只需要重新加载更新最后一页即可

            for i, data in enumerate(r.data['eps']['docs']):
                index = (page - 1) * limit + i
                if len(info.eps) > index:
                    epsInfo = info.eps[index]
                else:
                    epsInfo = BookEps()
                    info.eps.append(epsInfo)
                ToolUtil.ParseFromData(epsInfo, data)

            loadPage = int((len(info.eps) - 1) / limit + 1)
            nextPage = page + 1
            # 如果已经有了,则从最后那一页加载起就可以了
            if loadPage > nextPage:
                nextPage = loadPage

            info.eps.sort(key=lambda a: a.order)

            if nextPage <= pages:
                self.server.Send(req.GetComicsBookEpsReq(bookId, nextPage),
                                 bakParam=backData.bakParam,
                                 isASync=False)
                return Status.WaitLoad
            return Status.Ok
        except Exception as es:
            import sys
            cur_tb = sys.exc_info()[
                2]  # return (exc_type, exc_value, traceback)
            e = sys.exc_info()[1]
            Log.Error(cur_tb, e)
            return Status.Error
Exemplo n.º 2
0
    def AddBookEpsInfoBack(self, backData):
        # 此处在线程中加载后续章节 TODO 章节太多时会导致太慢
        try:
            r = backData.res
            bookId = backData.req.bookId
            info = self.books.get(bookId)
            info.epsCount = r.data['eps']["total"]
            page = r.data['eps']["page"]

            # 重新初始化
            pages = r.data['eps']["pages"]
            limit = r.data['eps']["limit"]
            # 优化,如果分页已经加载好了,只需要重新加载更新最后一页即可

            for i, data2 in enumerate(r.data['eps']['docs']):
                # index = (page -1) * limit + i
                epsId = data2.get('id')
                if epsId in info.epsDict:
                    epsInfo = info.epsDict[epsId]
                else:
                    epsInfo = BookEps()
                    info.epsDict[epsId] = epsInfo
                    # info.eps.append(epsInfo)
                ToolUtil.ParseFromData(epsInfo, data2)

            loadPage = int((len(info.epsDict) - 1) / limit + 1)
            nextPage = page + 1
            # 如果已经有了,则从最后那一页加载起就可以了
            if loadPage > nextPage:
                nextPage = loadPage

            info.eps = list(info.epsDict.values())
            info.eps.sort(key=lambda a: a.order)

            if nextPage <= pages:
                self.server.Send(req.GetComicsBookEpsReq(bookId, nextPage),
                                 bakParam=backData.bakParam,
                                 isASync=False)
                return Status.WaitLoad
            return Status.Ok
        except Exception as es:
            Log.Error(es)
            return Status.Error
Exemplo n.º 3
0
 def AddBookEpsInfo(self, bookId, bakParam):
     page = 1
     self.server.Send(req.GetComicsBookEpsReq(bookId, page),
                      bakParam=bakParam)