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 _Init(self): #提取所有用户DB文件 lstFile = myIO.getFiles(self.Dir_DataDB, '.csv', True) #循环提取所有 self.usrBills = {} #当前用户账单信息字典 for x in lstFile: usrID = myIO.getFileName(x) bills = myObj_Bills(usrID, self.Dir_DataDB) self.usrBills[usrID] = bills return True
def SwapData_BackUp(self, path, dir=""): fileName = myIO.getFileName(path, False) if (dir == ""): dir = self.dirSwap_back destDir = dir + "/" + fileName[len(self.tagName) + 1:len(self.tagName) + 11] try: myIO.mkdir(destDir, False, False) if (os.path.exists(destDir + "/" + fileName) == False): myIO.copyFile(path, destDir, fileName, False) if (os.path.exists(destDir + "/" + fileName)): os.remove(path) except: pass
def copyFiles_upload(): files = myIO.getFiles(jobDir + "/taskfeed/") for x in files: if (os.path.isdir(x)): if (len(myIO.getFiles(x)) == 0): myIO.deldir(x) continue fileName = myIO.getFileName(x) picDir = "" if ("pic_" in fileName): picDir = "/" + fileName[0:17] infos = fileName.split('_') targetDir = localDir2 + "/" + infos[1][0:6] + "/" + infos[ 1] + picDir myIO.copyFile(x, targetDir, '', False)
def DecryptFiles(file_dir, autoDel=True): files = myIO.getFiles(file_dir) for x in files: if (os.path.exists(x)): fileName = myIO.getFileName(x) if (fileName[len(fileName) - 4:] == "_key"): path = x.replace("_key.json", ".json") try: strJson = decrypt(x, path) # 解密 # 解密后删除 if (os.path.exists(path)): os.remove(x) except Exception as err: print('文件解密失败(%s)' % fileName + " ,具体错误描述为:%s" % err) pass
def _Run_UnLock(_path_): # 提取脚本路径 strName = myIO.getFileName(_path_) strPath = os.path.split( os.path.realpath(_path_))[0] + "/" + strName + ".lock" #文件删除 isDone = True lockfile = gol._Get_Setting(strPath, None) if (lockfile != None): try: lockfile.close() #关闭独占 os.remove(strPath) except: isLock = False isLock = not os.path.exists(strPath) return isLock
def Login_getCaptcha(self, imgPath, useLoacal=False): if (useLoacal): captcha_code = input("输入验证码:") else: # 读取图片文件 img_str = myIO.getImage_Str(imgPath) if (img_str == ""): return "" else: # 调用API,人工识别验证码 pWeb = myWeb("http://39.105.196.175:8668") # 组装请求参数 req = { "params": { "imgName": myIO.getFileName(imgPath, False), "imgData": img_str, "usrName": "茶叶一主号" } } # 调用API,轮询请求打码结果 r = pWeb.Do_Post("zxcAPI/robot/captcha_img", req, "验证码", True, True, True) res = myData_Trans.Tran_ToDict(r.decode()) if (res.get("res", "" == "OK")): msgID = res['msgID'] ind = 0 # 轮询调用API while (True): # 轮询提取人工识别结果 r = pWeb.Do_API_get( F"zxcAPI/robot/captcha/code/{msgID}", "验证码结果").strip().replace("\"", "") if (r != ""): lstR = r.split(',') captcha_code = lstR[len(lstR) - 1] break # 超时检测 if (ind > 60): return False ind += 1 time.sleep(3) return captcha_code
def _Run_Lock(_path_): # 提取脚本路径 strName = myIO.getFileName(_path_) strPath = os.path.split( os.path.realpath(_path_))[0] + "/" + strName + ".lock" isDone = True if (os.path.exists(strPath)): # 尝试删除,如果删除失败则运行中 try: os.remove(strPath) except: isDone = False isDone = not os.path.exists(strPath) #创建锁定 if (isDone): lockfile = codecs.open(strPath, 'w+', 'utf-8') gol._Set_Setting(strPath, lockfile) #pFile.close() #不关闭保持独占 else: print("脚本已启动! --" + strPath) gol._Close() return isDone