def get(self): #载入配置 code_id=request.args.get('code_id', "") code_name=request.args.get('code_name', "") lstStock = stocksInfo._Find(code_id, code_name) lstExtypes = [] lstCode_id = [] lstCode_Name = [] lstCode_NameEN = [] for x in lstStock: lstExtypes.append(x.extype) lstCode_id.append(x.code_id) lstCode_Name.append(x.code_name) lstCode_NameEN.append(x.code_name_En) jsonStocks = myData_Json.Json_Object() jsonStocks["extypes"] = lstExtypes jsonStocks["code_ids"] = lstCode_id jsonStocks["code_names"] = lstCode_Name jsonStocks["code_namesEN"] = lstCode_NameEN pMsg = copy.deepcopy(gol._Get_Setting('Return_strFormat', {})) pMsg['result'] = True pMsg['datas'] = jsonStocks._dict_ #return myData_Json.Trans_ToJson_str(pMsg) #使用jsonify来讲定义好的数据转换成json格式,并且返回给前端 return jsonify(pMsg)
def loadSets(self): #初始根目录信息 strDir, strName = myIO.getPath_ByFile(__file__) self.Dir_Base = os.path.abspath(os.path.join(strDir, "..")) self.Dir_Setting = self.Dir_Base + "/myWeb/Setting" #载入配置 text = myIO.getContent(self.Dir_Setting + "/BillTypes.json", True, False) self.jsonSets = myData_Json.Json_Object() self.jsonSets.Trans_FromStr(text)
def SwapData_In(self, nStepSwaps=1): nums = 0 lstDatas = [] nStepSwaps = myData.iif(nStepSwaps <= 0, sys.maxsize, nStepSwaps) lstFiles = myIO.getFiles(self.dirSwap, wildcard=".json", iswalk=False) if (len(lstFiles) < 1): return lstDatas myDebug.Print("DataSwap IOFiles::") myDebug.Print("\t" + self.dirSwap) myDebug.Print("\tSwap IOFiles(" + str(len(lstFiles)) + ")") for file in lstFiles: fileName = myIO.getFileName(file, True) if (fileName[0:len(self.tagName)] != self.tagName): continue if (self.checkNeedAck(fileName)): continue # 超时校检 if (self.delayedTime > 0): #解析时间并校检 timeTag = fileName[len(self.tagName) + 1:] timeData = myData_Trans.Tran_ToDatetime( timeTag, "%Y-%m-%d-%H-%M-%S") dtNow = datetime.datetime.now() if ((dtNow - timeData).seconds > self.delayedTime): self.SwapData_BackUp(file) continue #读取文件内容 myDebug.Print("\tnew file swap:: " + myIO.getFileName(file, False)) strJson = myIO.getContent(file, noBOM=True) pJson = myData_Json.Json_Object() pJson.Trans_FromStr(strJson) #组装交换信息 data = {"path": file, "fileInfo": pJson._dict_} lstDatas.append({"tagAck": fileName, "data": data}) #记录Ackinfo if (self.useAck): ackInfo = { "isAcked": False, "time": datetime.datetime.now(), "retrys": 0, "path": file } self.ackDict[fileName] = ackInfo else: self.SwapData_BackUp(file) nums += 1 if (nums >= nStepSwaps): break myDebug.Print("DataSwap IOFiles End." + "\tMargin Swap IOFiles(" + str(len(lstFiles) - len(lstDatas)) + ")\n") return lstDatas
def stockSetQuery(usrID): #strUrl = "http://" + request.remote_addr + ":8669/zxcAPI/robot" #实际网络地址在阿里云有问题,原因未明 strUrl = "http://127.0.0.1:8669/zxcAPI/robot" strPath = 'stock/QuoteSet/Query?usrID=' + usrID #设置查询接口执行 pWeb = myWeb_urlLib.myWeb(strUrl, bPrint=False) strReturn = pWeb.Do_API_get(strPath, "zxcAPI-py") print("查询结果:\n", strUrl, "--\n", strReturn, "\n") jsonRes = myData_Json.Trans_ToJson(strReturn) #结果处理 jsonRetrun = myData_Json.Json_Object(jsonRes['text']) return jsonRetrun.ToString()
def SwapData_OutFile(self, tagName="", dirDest=""): dataOut = copy.copy(self.dataOut) self.dataOut = [] if (len(dataOut) < 1): return False jsonData = myData_Json.Json_Object(dataOut) dirOut = myData.iif(dirDest != "", dirDest, self.dirSwap_out) + "/" if (tagName == ""): tagName = self.tagName if (tagName == "" and dirOut == ""): return False fileName = tagName + myData_Trans.Tran_ToDatetime_str( None, "_%Y_%m_%d_%H_%M_%S") + ".json" content = jsonData.ToString(autoFormat=False).replace("\\", "/") myIO.Save_File(dirOut + fileName, content, True, False) #myDebug.Print("DataSwap Out IOFiles::" + dirOut + fileName) myDebug.Print("DataSwap Out IOFiles::" + fileName) return True
def companyQuery(): #载入配置 company_id = request.args.get('company_id', "") company_name = request.args.get('company_name', "") print(company_id, company_name) dbCompany = gol._Get_Value('dbCompany') pCompany = dbCompany.getCompany(company_id, company_name) if (pCompany == None): pCompany = dbCompany.OnCreat_RowInfo() pCompany['companyID'] = company_id pCompany['companyName'] = company_name else: pCompany = pCompany.copy() #修正部分信息 jsonCompany = myData_Json.Json_Object(pCompany) return jsonCompany.ToString()
def usrInfoQuery(): name = request.args.get('name', "") phone = request.args.get('phone', "") pUsers = gol._Get_Setting('sysUsers', None) #实例 用户对象集 users = pUsers._Find_ByRealInfo(name, phone) jsonUsers = myData_Json.Json_Object() lstUsers = [] lstPhones = [] lstAddress = [] for x in users: lstUsers.append(x.usrName_Full) lstPhones = lstPhones + x.usrPhones lstAddress = lstAddress + x.usrAddresss jsonUsers["usrName_Fulls"] = lstUsers jsonUsers["usrPhones"] = lstPhones jsonUsers["usrAddresss"] = lstAddress return jsonUsers.ToString()
def _checkIot_CmdsState_doing_Meter(self, ids): # 操作任务状态查询 if (len(ids) < 1): return True data = {'ids': myData_Trans.Tran_ToStr(ids)} resp = self._DoWeb_Post("抄表记录状态", "admin/meter_task/state_update", data, {}) soup = BeautifulSoup(resp.content.decode('unicode-escape'), 'lxml') # 提取任务状态信息内容 pJson = myData_Json.Json_Object() pJson.Trans_FromStr(soup.string) pDatas = pJson['data'] for x in pDatas: #通知任务状态 taskInfo = dict(x) taskInfo['type'] = 'meter' self.Notify_CmdState(taskInfo) return True
def companyQuery(): #载入配置 company_id = request.args.get('company_id', "") company_name = request.args.get('company_name', "") print(company_id, company_name) dbCompany = gol._Get_Value('dbCompany') pCompany = dbCompany.getCompany(company_id, company_name).copy() if (pCompany == None): pCompany = dbCompany.OnCreat_RowInfo() pCompany['companyID'] = company_id pCompany['companyName'] = company_name #修正部分信息 pCompany['companyHasProcess'] = myData.iif( pCompany['companyHasProcess'], "是", "否") if (type(pCompany['companyRedate']) == datetime.datetime): pCompany['companyRedate'] = myData_Trans.Tran_ToDatetime_str( pCompany['companyRedate'], "%Y-%m-%d") jsonCompany = myData_Json.Json_Object(pCompany) return jsonCompany.ToString()
def get(self, msgInfo): pMsg = copy.deepcopy(gol._Get_Setting('Return_strFormat', {})) if (msgInfo == ""): return pMsg #初始消息处理对象 usrMMsg = gol._Get_Setting('manageMsgs', None) #提取消息管理器 if (usrMMsg == None): return pMsg #消息处理(应为异步处理) #msg = ast.literal_eval(msgInfo) pJson = myData_Json.Json_Object() pJson.Trans_FromStr(msgInfo) msg = pJson._dict_ msg['msg'] = msg['msg'].replace("※r※", "\r").replace( "※n※", "\n").replace("※i※", '"').replace("※t※", "\t").replace("※h※", "/") usrMMsg.OnHandleMsg(msg, 'wx', True) pMsg['result'] = True pMsg['text'] = "Swap Cached!" myDebug.Debug("API Msg-->>", str(msg)) return pMsg
def stockQuery(): #载入配置 code_id = request.args.get('code_id', "") code_name = request.args.get('code_name', "") pStocks = gol._Get_Value('setsStock', None) lstStock = pStocks._Find(code_id, code_name) lstExtypes = [] lstCode_id = [] lstCode_Name = [] lstCode_NameEN = [] for x in lstStock: lstExtypes.append(x.extype) lstCode_id.append(x.code_id) lstCode_Name.append(x.code_name) lstCode_NameEN.append(x.code_name_En) jsonStocks = myData_Json.Json_Object() jsonStocks["extypes"] = lstExtypes jsonStocks["code_ids"] = lstCode_id jsonStocks["code_names"] = lstCode_Name jsonStocks["code_namesEN"] = lstCode_NameEN return jsonStocks.ToString()