def createIndex(self, tableName, indexType, indexName, fieldNames): # 查询 表索引是否存在 nState = 0 if (self.isExist_Index(tableName, indexName) == True): myDebug.Debug(f'表{tableName}索引{indexName}已存在.\n') return nState else: myDebug.Debug(f"开始创建表索引{indexName}......") try: indexType = indexType.strip().lower() if (indexType == 'unique'): indexType += " index" if (indexType == 'primary'): indexType += " key" indexName = "" rs = self.execute( "", f'ALTER TABLE {tableName} ADD {indexType} {indexName}({fieldNames});' ) nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表{tableName}索引{indexName}创建完毕!\n') return nState
def _DoWeb_Post(self, strTag="", url="", data=None, checkInfo={}, bDebug=True): self._webReferer = self._webHost + "/" + url if (bDebug): myDebug.Debug("请求" + strTag + "页面:" + self._webReferer) #方便调试区分真实登录,和本地cookie if (len(self._webCookies) > 0): resp = requests.post(self._webReferer, data, headers=self._webHeaders, cookies=self._webCookies) else: resp = self._webSession.post(self._webReferer, data) # 输出结果 #print(resp.content.decode('utf-8')) if (bDebug): myDebug.Debug(" ---请求完毕。\n") # 验证信息 if (len(checkInfo) > 0): pass return resp
def checkMsg(self, strMsg): try: myDebug.Debug("\r\n接收队列消息window::", strMsg) msgR = ast.literal_eval(strMsg) #时间校检, 十分钟内缓存数据有效(过早时间数据忽略) if (self.checkTimeOut(msgR)): myDebug.Debug("--队列消息已超时window::", strMsg) return True #消息处理 return self.handelMsg(msgR) except Exception as ex: myError.Error(ex) return True
def Done_ByMsg(self, msg, bOnHandleMsg = False): myDebug.Print("请求消息:: ", msg) if(msg == None): return None #提取消息内容(自定义格式类型 myManager_Msg.OnCreatMsg) usrID = msg.get('usrID', "") usrName = msg.get('usrName', "") usrNameNick = msg.get('usrNameNick', "") nameSelf = msg.get('usrNameSelf', "") groupID = msg.get('groupID', "") groupName = msg.get('groupName', "") msgText = msg.get('msg', "") msgID = msg.get('msgID', "") msgType = msg.get('msgType', "") plat = msg.get('usrPlat', "") #按消息类型进一步处理('TEXT', 'IMAGE', 'VOICE', 'VIDEO') if(msgType == myManager_Msg.myMsgType.TEXT): msgText = msgText elif(msgType == myManager_Msg.myMsgType.PICTURE): #图片文件进行解析 msgText = msgText #调用 msgRs = self.Done(usrID, usrName, usrNameNick, msgText, msgID, msgType, plat, groupID, groupName, nameSelf) #推送结果至消息管理器 if(bOnHandleMsg): for msgR in msgRs: #处理所有返回消息,忽略无内容的 if(msgR == None): continue if(msgR.get('msg', "") == ""): continue self.OnHandleMsg(msgR) #消息处理 myDebug.Debug("处理消息::", msgR) return msgRs
def dropDB(self, dbName): # 查询 数据库是否存在 nState = 0 if (self.isExist_DB(dbName) == False): myDebug.Debug(f'{dbName}不存在.\n') return nState else: myDebug.Debug(f"开始删除库{dbName}......") try: rs = self.execute(dbName, f'DROP DATABASE {dbName};') nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'库{dbName}删除完毕!\n') return nState
def dropTable(self, tableName): # 查询 数据库是否存在 nState = 0 if (self.isExist_Table(tableName) == False): myDebug.Debug(f'表{tableName}不存在.\n') return nState else: myDebug.Debug(f"开始删除表{tableName}......") try: rs = self.execute("", f'DROP TABLE {tableName};') nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表{tableName}删除完毕!\n') return nState
def OnRecvQuote(self, quoteData): #输出统计信息 pData = quoteData myDebug.Debug(pData.name, ", Price:", pData.lastPrice) #输出数据信息 pData.Print()
def thrd_Moniter_API_Quote(): time.sleep(10) #延时等待 pSource = init_Quote() while (pSource.isClosed == False): myDebug.Debug(myData_Trans.Tran_ToDatetime_str()) time.sleep(120) #延时等待 myQuote_Source.mainStart() #检查启动行情进程
def _Done(self, Text, msgID="", msgType="TEXT", usrInfo={}): #日志记录(屏蔽NOTE类型) if (msgType.upper() != "NOTE"): self.msgLogs.Log_ByDict(Text, msgID, msgType, usrInfo) myDebug.Debug("已记录消息:", Text, "(" + str(msgID) + ") ", msgType, " from::", str(usrInfo)) return ""
def handelMsg_Quote(self, typeCmd, tagCmd, infCmd, msg): #提取窗体 myDebug.Debug(F"处理行情({tagCmd})", ": ", infCmd) frm = self.initHwnd(typeCmd, tagCmd, "", "") if (frm != None): infCmd['typeCmd'] = typeCmd frm.initHwnd("", "", True, infCmd) return True
def dropField(self, tableName, fieldName): # 查询 表字段是否存在 nState = 0 if (self.isExist_Field(tableName, fieldName) == False): myDebug.Debug(f'表{tableName}字段{fieldName}不存在.\n') return nState else: myDebug.Debug(f"开始删除表字段{fieldName}......") try: rs = self.execute( dbName, f'ALTER TABLE {tableName} DROP {fieldName};') nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表{tableName}字段{fieldName}删除完毕!\n') return nState
def dropIndex(self, tableName, indexName): # 查询 表索引是否存在 nState = 0 if (self.isExist_Index(tableName, indexName) == False): myDebug.Debug(f'表{tableName}索引{indexName}不存在.\n') return nState else: myDebug.Debug(f"开始删除表索引{indexName}......") try: rs = self.execute( dbName, f'ALTER TABLE {tableName} DROP INDEX {indexName};') nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表{tableName}索引{indexName}删除完毕!\n') return nState
def initCursor(self, dbName=''): try: self.checkConnect(dbName) cur = self.dbCon.cursor() return cur except Exception as e: myDebug.Debug(f'error:{e}') return None
def createDB(self, dbName): # 查询 数据库是否存在 nState = 0 if (self.isExist_DB(dbName)): myDebug.Debug(f'{dbName}已经存在.\n') return nState else: myDebug.Debug(f"开始创建库{dbName}......") try: rs = self.execute( "", f'CREATE DATABASE {dbName} character set utf8mb4;') nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'库{dbName}创建完毕!\n') return nState
def OnRecvQuote(self, quoteDatas): #输出统计信息 pData = quoteDatas.data pData_S = quoteDatas.datasS_M.dataS_Day myDebug.Debug(pData.name, "Price:", pData.lastPrice, ",Price_A:", round(pData_S.average, 4), ",Valume:", pData_S.tradeVolume_End) #输出数据信息 pData.Print()
def Reply_Text(msg): #图片缓存 if (msg['MsgType'] == 49): msg.download(self.dirPic + "Temps/" + msg.fileName) time.sleep(1) if self.Auto_RreplyText: #提取回复消息内容 myDebug.Debug("消息接收::", msg['Content']) return self.Get_Msg_Back(msg) #格式化提取(兼容API方式,消息队列无返回)
def isExist_Field(self, tableName, fieldName): try: rs = self.execute("", f'SHOW COLUMNS FROM {tableName};') field_list = re.findall('(\'.*?\')', str(rs).lower()) field_list = [re.sub("'", '', each) for each in field_list] return fieldName.lower() in field_list except Exception as e: myDebug.Debug(f'error:{e}') return False
def isExist_Table(self, tableName): try: rs = self.execute("", 'show tables;') table_list = re.findall('(\'.*?\')', str(rs).lower()) table_list = [re.sub("'", '', each) for each in table_list] return tableName.lower() in table_list except Exception as e: myDebug.Debug(f'error:{e}') return False
def Done_ByMsg(self, msg, isGroup = False): if(msg == None): return None #提取消息内容(可能随wx版本变更) 参见 https://blog.csdn.net/zhizunyu2009/article/details/79000190 usrName_To = msg['ToUserName'] msgID = msg.get('NewMsgId',"") #消息ID msgType = msg['Type'].upper() #消息类型 msgTime = msg.get('CreateTime', 0) #消息时间 strText = msg['Text'] #消息内容 if(strText == []): return None #区分群与个人 idGroup = "" nameGroup = "" nameSelf = "" isFromSelf = False if(isGroup): usrID = msg.get('ActualUserName',"") #发消息人ID usrName = msg.get('ActualNickName',"") #发消息人昵称 nickName = msg.get('ActualNickName',"") #发消息人昵称 idGroup = msg['User'].get('UserName',"") #群ID nameGroup = msg['User'].get('NickName',"") #群名称 if(self.usrID == usrID): nameSelf = self.usrName #发消息人名称,调整为自己 usrName = self.usrName nickName = usrName else: #区分自己发送 usrID = msg.get('FromUserName',"") #发消息人ID usrName = msg['User'].get('RemarkName',"") #发消息人备注名称 nickName = msg['User'].get('NickName',"") #发消息人昵称 if(self.usrID == usrID): usrID = msg.get('ToUserName',"") #发消息ID,调整为目标用户 nameSelf = self.usrName #发消息人名称,调整为自己 if(usrName == ""): usrName = nickName #无MarkName使用nickName myDebug.Debug(nameSelf,",", usrID,",", usrName,",", nickName, ",", msgID, ",",strText, ",", idGroup, ",",nameGroup) #Note信息(增加Note标识及提取信息) noteMsg = self.get_NoteTag(msgType, msg, usrID) #按消息类型进一步修正处理('PICTURE', 'VOICE', 'VIDEO') if(msgType == myManager_Msg.myMsgType.PICTURE): strText = self.dirBase + "/Data/Pic/Temps/" + msg.fileName #消息测试 #msgR = {} #msgR["msgType"] = "TEXT" #msgR["msg"] = "msg:" + strText #msgR["usrName"] = usrID #msgR["isSelf"] = isFromSelf #return msgR #调用 return self.Done(usrID, usrName, nickName, strText, msgID, msgType, msgTime, idGroup, nameGroup, nameSelf, noteMsg, msg)
def isExist_DB(self, dbName): # 查询数据库是否存在 try: rs = self.execute("", 'show databases;') db_list = re.findall('(\'.*?\')', str(rs).lower()) db_list = [re.sub("'", '', each) for each in db_list] return dbName.lower() in db_list except Exception as e: myDebug.Debug(f'error:{e}') return False
def getTime(self, bMinute = False): if(not bMinute): if(self.datetime == None): self.datetime = myData_Trans.Tran_ToDatetime(self.date + " " + self.time) #print(self.datetime) return self.datetime else: times = self.time.split(":") datetime = myData_Trans.Tran_ToDatetime(self.date + " " + times[0] + ":" + times[1], "%Y-%m-%d %H:%M") myDebug.Debug(datetime , "-- New Minutes") return datetime
def createTable(self, tableName): # 查询 数据库是否存在 nState = 0 if (self.isExist_Table(tableName)): myDebug.Debug(f'表{tableName}已经存在.\n') return nState else: myDebug.Debug(f"开始创建表{tableName}......") try: my_table = f'CREATE TABLE {tableName}(' \ f'id INT NOT NULL AUTO_INCREMENT,' \ f'PRIMARY KEY (id)' \ f')CHARSET="utf8mb4"' rs = self.execute("", my_table) nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表{tableName}创建完毕!\n') return nState
def get(self, msgInfo): #初始消息处理对象 ms_Reply = init_Reply() #消息处理(应为异步处理) msg = ast.literal_eval(msgInfo) pReutrn = ms_Reply.OnHandleMsg(msg) myDebug.Debug("API-->>", pReutrn) try: return pReutrn except: return None
def callback_RecvMsg(self, body): if (self.isRunning): try: msg = ast.literal_eval(body) myDebug.Debug("接收队列消息robot::", msg['msg']) #调用消息处理(并推送消息管理器) self.Done_ByMsg(msg, True) return True except Exception as ex: myError.Error(ex) return True return False
def Run_Monitor_Cmd_ByMQ(self, strMsg): try: myDebug.Debug("接收队列消息wx::", strMsg) msgR = ast.literal_eval(strMsg) #时间校检, 十分钟内缓存数据有效(过早时间数据忽略) if (self.wxReply.Check_TimeOut(msgR)): myDebug.Debug("--队列消息已超时wx::", strMsg) return True #消息发送 if (msgR.get('groupID', '') != '' or msgR.get('groupName', '') != ''): #区分群、个人 self.Send_Msg(msgR['groupID'], msgR['groupName'], msgR['msg'], msgR['msgType'], 1) else: self.Send_Msg(msgR['usrID'], msgR['usrName'], msgR['msg'], msgR['msgType']) return True except Exception as ex: myError.Error(ex) return True
def get(self, user, text, type = "Text"): pMQ_Sender = gol._Get_Value('zxcMQ_Wx_Sender') if(pMQ_Sender == None): return False #生成命令并推送消息队列 msg = {'usrName': user, 'msg': text, 'msgType': type} pMQ_Sender.Send_Msg(pMQ_Sender.nameQueue, str(msg)) myDebug.Debug(pMQ_Sender.nameQueue, msg) try: return True except : return False
def createField(self, tableInfo): # 循环所有字段信息 nState = 0 tableName = tableInfo["tb_name"] for i in range(len(tableInfo['fields'])): fieldInfo = tableInfo['fields'][i] # 创建字段 if (self.isExist_Field(tableName, fieldInfo['columnName'])): try: rs = self.editField(tableName, fieldInfo) nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 else: myDebug.Debug(f"开始创建表字段{fieldInfo['columnName']}......") try: field_length = fieldInfo.get("fieldLength", 0) field_length = myData.iif(field_length > 0, f"({str(field_length)})", " ") field_notnull = myData.iif( fieldInfo.get("nullable", False), "", "NOT NULL") field_default = fieldInfo.get("columnDefault", '') field_default = myData.iif(field_default == '', '', f'default {field_default}') ad_col = f'alter table {tableInfo["tb_name"]} add ' \ f'{fieldInfo["columnName"]} ' \ f'{fieldInfo["dataType"]}{field_length} ' \ f'{field_notnull} {field_default}' rs = self.execute("", ad_col) nState = myData.iif(rs == None, -1, 1) except Exception as e: myDebug.Debug(f'error:{e}') nState = -1 myDebug.Debug(f'表字段{fieldInfo["columnName"]}创建完毕!') myDebug.Debug(f'表{tableName}字段创建完毕!\n') return nState
def isExist_Index(self, tableName, indexName): try: rs = self.execute( "", f"SELECT * FROM information_schema.statistics WHERE TABLE_SCHEMA = '{self._dbName}' AND TABLE_NAME = '{tableName}' AND index_name = '{indexName}';" ) field_list = re.findall('(\'.*?\')', str(rs).lower()) field_list = [re.sub("'", '', each) for each in field_list] return indexName.lower() in field_list except Exception as e: myDebug.Debug(f'error:{e}') return False
def clossCursor(self, cur, bCommit=True, bCloseCon=False): try: # 提交更新,关闭游标 if (bCommit): self.dbCon.commit() if (cur != None): cur.close() if (bCloseCon and self.dbCon != None): if (self.dbCon.open): self.dbCon.close() return True except Exception as e: myDebug.Debug(f'error:{e}') return False
def Get_Msg_Back(self, msg, isGroup=False): #回复操作调用 msgR = self.wxReply.Done_ByMsg(msg, isGroup) #兼容API方式,消息队列无返回 if (msgR == None): return None #回复自己判断(调整为目标用户) myDebug.Debug("消息回复::", msgR) if (msgR.get('groupName', '') == ''): #区分群、个人 self.Send_Msg(msgR['usrID'], msgR['usrName'], msgR['msg'], msgR['msgType']) else: self.Send_Msg(msgR['groupID'], msgR['groupName'], msgR['msg'], msgR['msgType'], 1) return None