def DelHistory(self, bookId): query = QSqlQuery(self.db) sql = "delete from history where bookId='{}'".format(bookId) suc = query.exec_(sql) if not suc: Log.Warn(query.lastError().text()) return
def AddHistory(self, bookId, name, epsId, index, url, path): tick = int(time.time()) info = self.history.get(bookId) if not info: info = QtHistoryData() self.history[bookId] = info info.bookId = bookId info.name = name info.epsId = epsId info.picIndex = index info.url = url info.path = path info.tick = tick query = QSqlQuery(self.db) sql = "INSERT INTO history(bookId, name, epsId, picIndex, url, path, tick) " \ "VALUES ('{0}', '{1}', {2}, {3}, '{4}', '{5}', {6}) " \ "ON CONFLICT(bookId) DO UPDATE SET name='{1}', epsId={2}, picIndex={3}, url = '{4}', path='{5}', tick={6}".\ format(bookId, name, epsId, index, url, path, tick) suc = query.exec_(sql) if not suc: Log.Warn(query.lastError().text()) return
def Refresh(self, clsName, des='', checkTime=100): t2 = time.time() diff = int((t2 - self._t1) * 1000) if diff >= checkTime: text = 'CTime2 consume:{} ms, {}.{}'.format(diff, clsName, des) Log.Warn(text) self._t1 = t2 return diff
def _wrapper(*args, **kwargs): start = time.time() rt = fn(*args, **kwargs) diff = int((time.time() - start) * 1000) if diff >= 100: clsName = args[0] strLog = 'time_me consume,{} ms, {}.{}'.format( diff, clsName, fn.__name__) # Log.w(strLog) Log.Warn(strLog) return rt
def __init__(self, owner): super(self.__class__, self).__init__(owner) Ui_History.__init__(self) self.setupUi(self) self.owner = weakref.ref(owner) self.bookList = QtBookList(self, self.__class__.__name__) QtBookListMenu.__init__(self) self.bookList.InitBook(self.LoadNextPage) self.gridLayout_3.addWidget(self.bookList) self.pageNums = 20 self.lineEdit.setValidator(QtIntLimit(1, 1, self)) self.history = {} self.db = QSqlDatabase.addDatabase("QSQLITE", "history") self.db.setDatabaseName("history.db") if not self.db.open(): Log.Warn(self.db.lastError().text()) query = QSqlQuery(self.db) sql = """\ create table if not exists history(\ bookId varchar primary key,\ name varchar,\ epsId int, \ picIndex int,\ url varchar,\ path varchar,\ tick int\ )\ """ suc = query.exec_(sql) if not suc: a = query.lastError().text() Log.Warn(a) self.LoadHistory()
def AddBookByIdBack(self, backData): try: if backData.res.data.get("comic"): info = self.books.get(backData.res.data['comic']['_id']) if not info: info = Book() ToolUtil.ParseFromData(info, backData.res.data['comic']) self.books[info.id] = info return Status.Ok else: Log.Warn("未找到书籍, bookId:{}".format(backData)) return Status.NotFoundBook except Exception as es: Log.Error(es) return Status.NetError
def AddBookByIdBack(self, backData): try: if backData.res.data.get("comic"): info = self.books.get(backData.res.data['comic']['_id']) if not info: info = Book() ToolUtil.ParseFromData(info, backData.res.data['comic']) self.books[info.id] = info return Status.Ok else: Log.Warn("未找到书籍, bookId:{}".format(backData)) return Status.NotFoundBook 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.NetError
def HandlerTask2(self, taskId, data): try: info = self.tasks.get(taskId) if not info: Log.Warn("[Task] not find taskId:{}, {}".format(taskId, data)) return assert isinstance(info, QtHttpTask) if info.cleanFlag: taskIds = self.flagToIds.get(info.cleanFlag, set()) taskIds.discard(info.taskId) if info.backParam is None: info.callBack(data) else: info.callBack(data, info.backParam) del info.callBack del self.tasks[taskId] except Exception as es: Log.Error(es)
def RunLoad2(self): while True: info = self.LoadData() if not info: break t1 = CTime() data, convertId, taskId, tick = info if taskId not in self.convertLoad: continue if not data: lenData = 0 else: lenData = len(data) Log.Warn( "convert suc, taskId: {}, dataLen:{}, sts:{} tick:{}".format( str(taskId), lenData, str(convertId), str(tick))) info = self.convertLoad[taskId] assert isinstance(info, QtDownloadTask) info.saveData = data info.tick = tick self.convertBack.emit(taskId) t1.Refresh("RunLoad")
def HandlerTask2(self, taskId, data): try: info = self.tasks.get(taskId) if not info: Log.Warn("[Task] not find taskId:{}, {}".format(taskId, data)) return assert isinstance(info, QtHttpTask) if info.cleanFlag: taskIds = self.flagToIds.get(info.cleanFlag, set()) taskIds.discard(info.taskId) if info.backParam is None: info.callBack(data) else: info.callBack(data, info.backParam) del info.callBack del self.tasks[taskId] 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)
def on_error(self, ws, error): self.parent.websocket.emit(self.parent.Error, "") Log.Warn(error)