Exemplo n.º 1
0
 def InitBack(self, data):
     try:
         self.owner().loadingForm.close()
         self.bookList1.clear()
         self.bookList2.clear()
         data = json.loads(data)
         for categroys in data.get("data").get("collections"):
             if categroys.get("title") == "本子神推薦":
                 bookList = self.bookList1
             else:
                 bookList = self.bookList2
             for v in categroys.get('comics'):
                 title = v.get("title", "")
                 _id = v.get("_id")
                 url = v.get("thumb", {}).get("fileServer")
                 path = v.get("thumb", {}).get("path")
                 originalName = v.get("thumb", {}).get("originalName")
                 info = "完本," if v.get("finished") else ""
                 info += "{}E/{}P".format(str(v.get("epsCount")),
                                          str(v.get("pagesCount")))
                 bookList.AddBookItem(_id, title, info, url, path,
                                      originalName)
     except Exception as es:
         Log.Error(es)
         self.isInit = False
    def SendCommentChildrenBack(self, msg, index):
        try:
            item = self.listWidget.item(index)
            if not item:
                self.loadingForm.close()
                return
            widget = self.listWidget.itemWidget(item)
            if not widget:
                self.loadingForm.close()
                return

            data = json.loads(msg)
            if data.get("code") == 200:
                self.owner().qtTask.AddHttpTask(lambda x: Server().Send(
                    req.GetCommentsChildrenReq(widget.id), bakParam=x),
                                                self.LoadCommentInfoBack,
                                                backParam=index,
                                                cleanFlag=self.closeFlag)
            else:
                self.loadingForm.close()
                QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误"))
            self.commentLine.setText("")
        except Exception as es:
            self.loadingForm.close()
            Log.Error(es)
Exemplo n.º 3
0
    def __call__(self, backData):
        if backData.status != Status.Ok:
            if backData.bakParam:
                QtTask().taskBack.emit(backData.bakParam, "")
        else:
            r = backData.res
            try:
                if r.status_code != 200:
                    if backData.bakParam:
                        QtTask().taskBack.emit(backData.bakParam, "")
                    return

                fileSize = int(r.headers.get('Content-Length', 0))
                getSize = 0
                now = time.time()
                consume = 1
                for chunk in r.iter_content(chunk_size=10240):
                    getSize += len(chunk)
                    consume = time.time() - now
                    if consume >= 2:
                        break

                downloadSize = getSize / consume
                speed = ToolUtil.GetDownloadSize(downloadSize)
                if backData.bakParam:
                    QtTask().taskBack.emit(backData.bakParam, speed)

            except Exception as es:
                Log.Error(es)
                if backData.bakParam:
                    QtTask().taskBack.emit(backData.bakParam, "")
Exemplo n.º 4
0
 def SendSearchBack(self, raw):
     self.owner().loadingForm.close()
     try:
         self.bookList.UpdateState()
         data = json.loads(raw)
         if data.get("code") == 200:
             info = data.get("data").get("comics")
             page = int(info.get("page"))
             pages = int(info.get("pages"))
             self.bookList.UpdatePage(page, pages)
             self.jumpLine.setValidator(QtIntLimit(1, pages, self))
             pageText = "页:" + str(self.bookList.page) + "/" + str(self.bookList.pages)
             self.label.setText(pageText)
             for v in info.get("docs", []):
                 title = v.get("title", "")
                 _id = v.get("_id")
                 url = v.get("thumb", {}).get("fileServer")
                 path = v.get("thumb", {}).get("path")
                 originalName = v.get("thumb", {}).get("originalName")
                 info2 = "完本," if v.get("finished") else ""
                 info2 += "{}E/{}P".format(str(v.get("epsCount")), str(v.get("pagesCount")))
                 param = ",".join(v.get("categories"))
                 self.bookList.AddBookItem(_id, title, info2, url, path, param)
             self.CheckCategoryShowItem()
         else:
             # QtWidgets.QMessageBox.information(self, '未搜索到结果', "未搜索到结果", QtWidgets.QMessageBox.Yes)
             self.owner().msgForm.ShowError("未搜索到结果")
     except Exception as es:
         Log.Error(es)
     pass
Exemplo n.º 5
0
    def __call__(self, backData):
        if backData.status != Status.Ok:
            if backData.bakParam:
                QtTask().downloadBack.emit(backData.bakParam, -1, b"")
        else:
            r = backData.res
            try:
                if r.status_code != 200:
                    if backData.bakParam:
                        QtTask().downloadBack.emit(backData.bakParam, -1, b"")
                    return
                fileSize = int(r.headers.get('Content-Length', 0))
                getSize = 0
                data = b""
                for chunk in r.iter_content(chunk_size=1024):
                    if backData.bakParam:
                        QtTask().downloadBack.emit(backData.bakParam, fileSize-getSize, chunk)
                    getSize += len(chunk)
                    data += chunk
                if backData.bakParam:
                    QtTask().downloadBack.emit(backData.bakParam, 0, b"")
                # Log.Info("size:{}, url:{}".format(ToolUtil.GetDownloadSize(fileSize), backData.req.url))
                if backData.cacheAndLoadPath and config.IsUseCache and len(data) > 0:
                    filePath = backData.cacheAndLoadPath
                    fileDir = os.path.dirname(filePath)
                    if not os.path.isdir(fileDir):
                        os.makedirs(fileDir)

                    with open(filePath, "wb+") as f:
                        f.write(data)
                    Log.Debug("add download cache, cachePath:{}".format(filePath))
            except Exception as es:
                Log.Error(es)
                if backData.bakParam:
                    QtTask().downloadBack.emit(backData.bakParam, -1, b"")
Exemplo n.º 6
0
    def InitBack(self, raw, backParam):
        self.owner().loadingForm.close()
        try:
            if backParam == "H24":
                bookList = self.h24BookList
            elif backParam == "D7":
                bookList = self.d7BookList
            elif backParam == "D30":
                bookList = self.d30BookList
            else:
                assert False

            data = json.loads(raw)
            if data.get("code") == 200:
                for v in data.get("data").get("comics"):
                    title = v.get("title", "")
                    _id = v.get("_id")
                    url = v.get("thumb", {}).get("fileServer")
                    path = v.get("thumb", {}).get("path")
                    originalName = v.get("thumb", {}).get("originalName")
                    info = "完本," if v.get("finished") else ""
                    info += "{}E/{}P".format(str(v.get("epsCount")), str(v.get("pagesCount")))
                    bookList.AddBookItem(_id, title, info, url, path, originalName)
        except Exception as es:
            Log.Error(es)
            self.isInit = False
Exemplo n.º 7
0
    def GetCommnetBack(self, data):
        try:
            self.loadingForm.close()
            self.listWidget.UpdateState()
            msg = json.loads(data)
            if msg.get("code") == 200:
                comments = msg.get("data", {}).get("comments", {})
                topComments = msg.get("data", {}).get("topComments", [])
                page = int(comments.get("page", 1))
                pages = int(comments.get("pages", 1))
                limit = int(comments.get("limit", 1))
                self.listWidget.UpdatePage(page, pages)
                self.nums.setText("分页:{}/{}".format(str(page), str(pages)))
                total = comments.get("total", 0)
                # self.tabWidget.setTabText(1, "评论({})".format(str(total)))
                if page == 1:
                    for index, info in enumerate(topComments):
                        floor = "置顶"
                        content = info.get("content")
                        name = info.get("_user", {}).get("name")
                        avatar = info.get("_user", {}).get("avatar", {})
                        title = info.get("_user", {}).get("title", {})
                        level = info.get("_user", {}).get("level", 1)
                        createdTime = info.get("created_at")
                        commentsCount = info.get("commentsCount")
                        commnetId = info.get('_id')
                        likesCount = info.get("likesCount")
                        self.listWidget.AddUserItem(commnetId, commentsCount,
                                                    likesCount, content, name,
                                                    createdTime, floor,
                                                    avatar.get("fileServer"),
                                                    avatar.get("path"),
                                                    avatar.get("originalName"),
                                                    title, level)

                for index, info in enumerate(comments.get("docs")):
                    floor = total - ((page - 1) * limit + index)
                    content = info.get("content")
                    name = info.get("_user", {}).get("name")
                    avatar = info.get("_user", {}).get("avatar", {})
                    createdTime = info.get("created_at")
                    commentsCount = info.get("commentsCount")
                    commnetId = info.get('_id')
                    likesCount = info.get("likesCount")
                    title = info.get("_user", {}).get("title", "")
                    level = info.get("_user", {}).get("level", 1)
                    self.listWidget.AddUserItem(commnetId, commentsCount,
                                                likesCount, content, name,
                                                createdTime, floor,
                                                avatar.get("fileServer"),
                                                avatar.get("path"),
                                                avatar.get("originalName"),
                                                title, level)
            return
        except Exception as es:
            Log.Error(es)
Exemplo n.º 8
0
 def SendKeywordBack(self, raw):
     try:
         data = json.loads(raw)
         if data.get("code") == 200:
             self.keywordList.clear()
             for keyword in data.get('data', {}).get("keywords", []):
                 self.keywordList.AddItem(keyword)
             pass
         else:
             pass
     except Exception as es:
         Log.Error(es)
     pass
Exemplo n.º 9
0
 def JumpPage(self):
     try:
         page = int(self.lineEdit.text())
         if page > self.listWidget.pages:
             return
         self.listWidget.page = page
         self.listWidget.clear()
         self.loadingForm.show()
         QtTask().AddHttpTask(
             lambda x: Server().Send(req.GetComments(self.bookId, self.listWidget.page), bakParam=x),
             self.GetCommnetBack, cleanFlag=self.closeFlag)
     except Exception as es:
         Log.Error(es)
Exemplo n.º 10
0
 def SendCommentBack(self, msg):
     try:
         data = json.loads(msg)
         if data.get("code") == 200:
             self.ClearCommnetList()
             self.owner().qtTask.AddHttpTask(lambda x: Server().Send(req.GetComments(self.bookId), bakParam=x),
                                             self.GetCommnetBack, cleanFlag=self.closeFlag)
         else:
             self.loadingForm.close()
             QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误"))
         self.commentLine.setText("")
     except Exception as es:
         self.loadingForm.close()
         Log.Error(es)
Exemplo n.º 11
0
 def GetChatBack(self, data):
     try:
         data = json.loads(data)
         if data.get("code") == 200:
             infos = data.get("data", {}).get("chatList", {})
             for index, info in enumerate(infos):
                 name = info.get("title")
                 content = info.get("description")
                 # avatar = info.get("_user", {}).get("avatar", {})
                 # createdTime = info.get("created_at")
                 self.listWidget.AddUserItem(info.get("url"), "", "", content, name, "", index+1,
                                             info.get("avatar"),
                                             "", "")
     except Exception as es:
         Log.Error(es)
     return
Exemplo n.º 12
0
 def SendKeywordBack(self, raw):
     try:
         data = json.loads(raw)
         if data.get("code") == 200:
             self.keywordList.clear()
             for keyword in data.get('data', {}).get("keywords", []):
                 self.keywordList.AddItem(keyword)
             pass
         else:
             pass
     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)
     pass
Exemplo n.º 13
0
    def LoadCommentInfoBack(self, msg, index):
        try:
            self.loadingForm.close()
            item = self.listWidget.item(index)
            if not item:
                return
            widget = self.listWidget.itemWidget(item)
            if not widget:
                return
            self.childrenListWidget.UpdateState()
            data = json.loads(msg)
            self.childrenListWidget.parentId = index
            widget.gridLayout.addWidget(self.childrenWidget, 1, 0, 1, 1)
            if data.get("code") == 200:
                comments = data.get("data", {}).get("comments", {})
                page = int(comments.get("page", 1))
                total = int(comments.get("total", 1))
                pages = int(comments.get("pages", 1))
                limit = int(comments.get("limit", 1))
                self.childrenListWidget.UpdatePage(page, pages)
                for index, info in enumerate(comments.get("docs")):
                    floor = total - ((page - 1) * limit + index)
                    content = info.get("content")
                    name = info.get("_user", {}).get("name")
                    level = info.get("_user", {}).get("lv")
                    avatar = info.get("_user", {}).get("avatar", {})
                    createdTime = info.get("created_at")
                    commentsCount = info.get("commentsCount")
                    likesCount = info.get("likesCount")
                    commnetId = info.get('_id')
                    title = info.get("_user", {}).get("title", "")
                    level = info.get("_user", {}).get("level", 1)
                    self.childrenListWidget.AddUserItem(
                        commnetId, commentsCount, likesCount,
                        content, name, createdTime, floor,
                        avatar.get("fileServer"), avatar.get("path"),
                        avatar.get("originalName"), title, level)

                pass
            self.listWidget.scrollToItem(
                item, self.listWidget.ScrollHint.PositionAtTop)
            size = self.listWidget.size()
            item.setSizeHint(size)
        except Exception as es:
            Log.Error(es)
Exemplo n.º 14
0
 def InitRandomBack(self, data):
     try:
         self.owner().loadingForm.close()
         data = json.loads(data)
         self.bookList3.clear()
         for v in data.get("data").get('comics'):
             bookList = self.bookList3
             title = v.get("title", "")
             _id = v.get("_id")
             url = v.get("thumb", {}).get("fileServer")
             path = v.get("thumb", {}).get("path")
             originalName = v.get("thumb", {}).get("originalName")
             info = "完本," if v.get("finished") else ""
             info += "{}E/{}P".format(str(v.get("epsCount")),
                                      str(v.get("pagesCount")))
             bookList.AddBookItem(_id, title, info, url, path, originalName)
     except Exception as es:
         Log.Error(es)
Exemplo n.º 15
0
    def __call__(self, backData):
        if backData.status != Status.Ok:
            if backData.bakParam:
                QtTask().downloadBack.emit(backData.bakParam, -1, b"")
        else:
            r = backData.res
            try:
                if r.status_code != 200:
                    if backData.bakParam:
                        QtTask().downloadBack.emit(backData.bakParam, -1, b"")
                    return
                fileSize = int(r.headers.get('Content-Length', 0))
                getSize = 0
                data = b""
                for chunk in r.iter_content(chunk_size=1024):
                    if backData.bakParam:
                        QtTask().downloadBack.emit(backData.bakParam, fileSize-getSize, chunk)
                    getSize += len(chunk)
                    data += chunk
                if backData.bakParam:
                    QtTask().downloadBack.emit(backData.bakParam, 0, b"")

                if backData.req.isSaveCache and config.IsUseCache and len(data) > 0:
                    path = backData.req.path

                    filePath = os.path.join(os.path.join(config.SavePath, config.CachePathDir), os.path.dirname(path))

                    if not os.path.isdir(filePath):
                        os.makedirs(filePath)

                    a = hashlib.md5(path.encode("utf-8")).hexdigest()

                    with open(os.path.join(filePath, a), "wb+") as f:
                        f.write(data)
            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)
                if backData.bakParam:
                    QtTask().downloadBack.emit(backData.bakParam, -1, b"")