def redisOp(op_list, value): operation = [] operation.append(op_list[0]) operation.append(op_list[1]) operation.append(value) rs = RedisOp(operation) if rs[0]: re = [] re.append(True) return re else: re = [] re.append(False) re.append(rs[1]) return re
def process_data(iterator): sql_insert = generateInsertSQL("ITR23.RLT_ESCLT_KM_UPD_OPPTY_DTL_F", "RLT_ESCLT_KM_UPD_OPPTY_DTL_F.conf") dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] checkDataMd5 = '' # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) else: afterProcessArray.append(oneElement) else: afterProcessArray.append('NULL') key = 'ESCLT_KM_UPD_OPPTY_D' + '.' + str( afterProcessArray[0]) + '.' + str(afterProcessArray[1]) v = RedisOp(['get', key]) newArray = [] if v[0]: rs = v[1] newArray.append(int(rs[0])) else: pass if afterProcessArray[2] == "NULL": newArray.append(-2) else: key = 'ESCLT_D' + '.' + 'ESCLT_ID' + newArray[0] v1 = RedisOp(["get", key]) if v1[0]: rs = list(eval(v1[1])) if rs[1] == 'n': newArray.append(rs[0]) else: newArray.append(0) else: newArray.append(0) if afterProcessArray[3] == "NULL": newArray.append(-2) else: rs = RedisOp(["get", "HPSC_MSTR_L_CD_D"]) if rs[0]: v = list(eval(rs[1])) for i in v: if 'ML_KM_UPD_TYPE_KY' in i and afterProcessArray[ 3] in i: newArray.append(afterProcessArray[3]) else: newArray.append(0) for i in newArray: checkDataMd5 = checkDataMd5 + str(i) #check if the md5 are the same or existence md5_str = hashlib.md5(checkDataMd5).hexdigest() sole_key = 'ESCLT_KM_UPD_OPPTY_DTL_F' + str(newArray[0]) operation = [] operation.append("get") operation.append(sole_key) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str #update the data int the database update_sql = generateUpdateSql( "ITR23.RL_ESCLT_KM_UPD_OPPTY_DTL_F", "RLT_ESCLT_KM_UPD_OPPTY_DTL_F.conf", ["ESCLT_KM_UPD_OPPTY_KY", r_s[0]]) sql = update_sql % (tuple(newArray)) res = cursor.execute(sql) con.commit() RedisOp(["set", sole_key, r_s]) else: r_s = [] r_s.append(newArray[0]) #inster data to the database r = tuple(newArray) sql_v = sql_insert % r res = cursor.execute((sql_insert % r)) con.commit() r_s.append(md5_str) RedisOp(["set", sole_key, r_s])
def process_data(iterator): sql_insert = generateInsertSQL("ITR23.RLT_ESCLT_CPCTY_ISSUE_TYPE_D", "./RLT_ESCLT_CPCTY_ISSUE_TYPE_D.conf") dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] del oneTuple[2] checkDataMd5 = '' ESCLT_ID = str(oneTuple[0]) # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') #check if the md5 are the same or existence md5_str = hashlib.md5(checkDataMd5).hexdigest() sole_key = 'RLT_ESCLT_CPCTY_ISSUE_TYPE_D' + ESCLT_ID operation = [] operation.append("get") operation.append(sole_key) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str afterProcessArray.insert(0, r_s[0]) r = tuple(afterProcessArray) #update the data int the database update_sql = generateUpdateSql( "ITR23.RLT_ESCLT_CPCTY_ISSUE_TYPE_D", "RLT_ESCLT_CPCTY_ISSUE_TYPE_D.conf", ["ESCLT_CPCTY_ISSUE_TYPE_D_KY", r_s[0]]) res = cursor.execute(update_sql % r) con.commit() RedisOp(["set", sole_key, r_s]) else: res = RedisOp(["get", "ESCLT_CPCTY_ISSUE_TYPE_D_KY_count"]) r_s = [] if res[0]: count = int(res[1]) + 1 r_s.append(count) #inster data to the database afterProcessArray.insert(0, count) r = tuple(afterProcessArray) sql_v = sql_insert % r res = cursor.execute((sql_insert % r)) con.commit() RedisOp( ["set", "ESCLT_CPCTY_ISSUE_TYPE_D_KY_count", count]) else: r_s.append(1) #inster data to the database afterProcessArray.insert(0, 1) r = tuple(afterProcessArray) sql_v = sql_insert % r res = cursor.execute(sql_v) con.commit() RedisOp(["set", "ESCLT_CPCTY_ISSUE_TYPE_D_KY_count", 1]) r_s.append(md5_str) RedisOp(["set", sole_key, r_s])
def process_data(iterator): column = "ESCLT_RESTRT_SRVC_TYPE_D_KY,ESCLT_ID,REC_NR,RESTRT_SRVC_DTL_DN,CRC_CHCKSM_TX" value = "VALUES(%d,'%s',%d,'%s','%s')" sql_inster = "INSERT INTO ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D" + "(" + column + ")" + value dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] del oneTuple[2] checkDataMd5 = '' dvc_id = "ESCLT_RESTRT_SRVC_TYPE_D" + str(oneTuple[0]) + str( oneTuple[1]) # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') # check if the md5 are the same or existence md5_str = hashlib.md5(checkDataMd5).hexdigest() afterProcessArray.append(md5_str) operation = [] operation.append("get") operation.append(dvc_id) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str #Keep primary key & MD5 RedisOp(["set", dvc_id, r_s]) res = RedisOp(["get", "ESCLT_RESTRT_SRVC_TYPE_D_count"]) #count = int(res[1]) # update the data int the database #r = tuple(afterProcessArray) sql = "UPDATE ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D SET RESTRT_SRVC_DTL_DN= NULLIF('%s','NULL'),CRC_CHCKSM_TX='%s' WHERE ESCLT_ID= '%s' AND REC_NR = %d " % ( afterProcessArray[2], md5_str, afterProcessArray[0], afterProcessArray[1]) cursor.execute(sql) con.commit() else: res = RedisOp(["get", "ESCLT_RESTRT_SRVC_TYPE_D_count"]) r_s = [] if res[0]: count = int(res[1]) + 1 RedisOp(["set", "ESCLT_RESTRT_SRVC_TYPE_D_count", count]) r_s.append(count) # Keep data in redis for lookup #lkp_KY= "LKP_ESCLT_RESTRT_SRVC_TYPE_D_" + str(afterProcessArray[0]) + str(afterProcessArray[1]) #RedisOp(["set", lkp_KY, count]) # inster data to the database afterProcessArray.insert(0, count) r = tuple(afterProcessArray) #RedisOp(["set", "Rs", r]) sql_v = sql_inster % r #RedisOp(["set", "sql_v", sql_v]) cursor.execute((sql_inster % r)) con.commit() else: RedisOp(["set", "ESCLT_RESTRT_SRVC_TYPE_D_count", 1]) r_s.append(1) # Keep data in redis for lookup #lkp_KY= "LKP_ESCLT_RESTRT_SRVC_TYPE_D_" + str(afterProcessArray[0]) + str(afterProcessArray[1]) #RedisOp(["set", lkp_KY, 1]) # inster data to the database afterProcessArray.insert(0, 1) r = tuple(afterProcessArray) sql = sql_inster % r RedisOp(["set", "sql_v", sql]) res = cursor.execute(sql) con.commit() r_s.append(md5_str) RedisOp(["set", dvc_id, r_s])
import redis_hash from redis_hash import RedisOp from filter_ import dstct """ operation = ["get",TABLENAME] acording to tablename finding out corresponding datas return listA inpstr = ["val1","val2"....] then find one data by filter with inpstr return listB outstr = [n] find col n in the data return listC """ operation = ["get", "ESCLT_ACTN_D"] inpstr = [] outstr = [] r = RedisOp(operation) print r #res = dstct(r[1],inpstr,outstr) #print res
def process_data(iterator): sql_insert = generateInsertSQL("ITR23.RLT_ESCLT_AVL_D","./RLT_ESCLT_AVL_D.conf") dsn = cx_Oracle.makedsn(info["host"],info["port"],info["sid"]) con = cx_Oracle.connect(info["username"],info["passward"],dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] checkDataMd5 = '' avl_id = str(oneTuple[0]) # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None : if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') #check if the md5 are the same or existence operation = ["get","HPSC_MSTR_L_CD_D"] res_mstr = RedisOp(operation) list_res_mstr = list(eval(res_mstr[1])) for i in list_res_mstr: if afterProcessArray[4] in i: if i[6] == "ML_ESCLT_TYPE_KY": afterProcessArray[4] = i[8] checkDataMd5 = checkDataMd5 + str(afterProcessArray[4]) if i[8] == None: afterProcessArray[4] = 0 checkDataMd5 = checkDataMd5 + str(afterProcessArray[4]) elif afterProcessArray[4] == None: afterProcessArray[4] = -2 checkDataMd5 = checkDataMd5 + str(afterProcessArray[4]) operation = ["get","HPSC_MSTR_L_CD_D"] res_mstr = RedisOp(operation) list_res_mstr = list(eval(res_mstr[1])) for i in list_res_mstr: if afterProcessArray[4] in i: if i[6] == "ML_TMLNSS_TYPE_KY": afterProcessArray[5] = i[8] checkDataMd5 = checkDataMd5 + str(afterProcessArray[5]) if i[8] == None: afterProcessArray[5] = 0 checkDataMd5 = checkDataMd5 + str(afterProcessArray[5]) elif afterProcessArray[5] == None: afterProcessArray[5] = -2 checkDataMd5 = checkDataMd5 + str(afterProcessArray[5]) operation = ["get","CI_D"] res_ci = RedisOp(operation) list_res_ci = list(eval(res_ci[1])) for i in list_res_ci: if afterProcessArray[10] in i : afterProcessArray[10] = i[1] checkDataMd5 = checkDataMd5 + str(afterProcessArray[10]) if i[1] == None: afterProcessArray[10] = 0 checkDataMd5 = checkDataMd5 + str(afterProcessArray[10]) elif i[1] == None: afterProcessArray[10] = -2 checkDataMd5 = checkDataMd5 + str(afterProcessArray[10]) operation = ["get","HP_CO_TO_SPRN_CO_MAPG"] res_sprn = RedisOp(operation) list_res_sprn = list(eval(res_sprn[1])) for i in list_res_sprn: if afterProcessArray[11] in i: afterProcessArray[11] == i[1] checkDataMd5 = checkDataMd5 + str(afterProcessArray[10]) md5_str = hashlib.md5(checkDataMd5).hexdigest() operation = [] operation.append("get") operation.append(avl_id) rs = RedisOp(operation) avl_id = 'RLT_ESCLT_AVL_D' + avl_id if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str #update the data int the database update_sql = generateUpdateSql("ITR23.RLT_ESCLT_AVL_D","RLT_ESCLT_AVL_D.conf",["ESCLT_AVL_D_KY",r_s[0]]) res=cursor.execute(info["sql"]) con.commit() RedisOp(["set",avl_id,r_s]) else: res = RedisOp(["get","ESCLT_AVL_D_count"]) r_s = [] if res[0]: count = int(res[1]) + 1 r_s.append(count) #inster data to the database afterProcessArray.insert(0,count) r = tuple(afterProcessArray) RedisOp(["set","Rs_ESCLT_AVL_D",r]) sql_v = sql_insert%r RedisOp(["set","sql_v_ESCLT_AVL_D_KY",sql_v]) res=cursor.execute((sql_insert%r)) con.commit() RedisOp(["set","ESCLT_AVL_D_count",count]) else: r_s.append(1) #inster data to the database afterProcessArray.insert(0,1) r = tuple(afterProcessArray) RedisOp(["set","Rs_ESCLT_AVL_D",r]) sql_v = sql_insert%r RedisOp(["set","sql_v_ESCLT_AVL_D_KY",sql_v]) res=cursor.execute(sql) con.commit() RedisOp(["set","ESCLT_AVL_D_count",1]) r_s.append(md5_str) RedisOp(["set",avl_id,r_s])
def process_data(iterator): #column = "ESCLT_DVC_D_KY,ESCLT_DVC_ID,ESCLT_ID,ESCLT_CI_LGCL_NM,IT_ASSET_OWN_ORG_HIER_TX,IT_ASSET_OWN_ORG_HIER_ID,SUPP_OWN_ORG_HIER_TX,SUPP_OWN_ORG_HIER_ID,APP_PRTFL_ID,SITE_TO_SITE_ENBL_FG,SITE_TO_SITE_STAT_TX,LAST_AVL_EVNT_STRT_DT,LAST_AVL_EVNT_END_DT,LAST_AVL_EVNT_ID,DVC_TYPE_NM,PRIM_CI_FG,LAST_UPD_TS,LAST_UPD_USER_NM,S2S_RDY_FG,INSTNC_PRTFL_ID" #value = "VALUES(%d,%d,DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),%d,DECODE('%s','NULL',NULL),%d,%d,DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),NVL(TO_NUMBER(%s),NULL),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_NUMBER(%s),NULL))" #sql_inster = "INSERT INTO ITR23.RLT_ESCLT_DVC_D" + "(" + column + ")" + value column = "ESCLT_MGMT_D_KY,PRBLM_CI_D_KY,DATA_WHSE_ROW_ID" value = "VALUES(%d,%d,%d)" sql_inster = "INSERT INTO ITR23.RLT_ESCLT_PRBLM_CI_RELSHP_F" + "(" + column + ")" + value #sel_upd = "UPDATE ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D SET RESTRT_SRVC_DTL_DN='%s' WHERE ESCLT_RESTRT_SRVC_TYPE_D_KY=%d" dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] #delElement = [13, 12, 11, 9] #for i in delElement: del oneTuple[1] checkDataMd5 = '' #lkp ESCLT_MGMT_D_KY cursor.execute( "SELECT DISTINCT ESCLT_MGMT_D_KY FROM ITR23.ESCLT_D WHERE ESCLT_ID = '%s'" % oneTuple[0]) row = cursor.fetchone() if row != None: oneTuple.append(row[0]) else: oneTuple.append(0) #lkp PROBELM_CI_D_KY if oneTuple[1] != None: cursor.execute( "SELECT DISTINCT CI_D_KY FROM ITR23.CI_D WHERE LOWER (CI_LGCL_NM) = '%s'" % (oneTuple[1])) row = cursor.fetchone() if row != None: oneTuple.append(row[0]) else: oneTuple.append(0) else: oneTuple.append(-2) del oneTuple[0] del oneTuple[0] dvc_id = "RLT_ESCLT_PRBLM_CI_RELSHP_F" + str(oneTuple[0]) + str( oneTuple[1]) #oneTuple.append(oneTuple[2]) #delElement = [2] #Remove ML_RSTAT_SEVC_TYPE_KY,exits in L1(3th),do not needed in D #for i in delElement: # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') # check if the md5 are the same or existence md5_str = hashlib.md5(checkDataMd5).hexdigest() #afterProcessArray.append(md5_str) operation = [] operation.append("get") operation.append(dvc_id) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str #RedisOp(["set", dvc_id, r_s]) RedisOp(["set", dvc_id, r_s]) res = RedisOp(["get", "RLT_ESCLT_PRBLM_CI_RELSHP_F_count"]) count = int(res[1]) #afterProcessArray.insert(0, count) afterProcessArray.append(count) # update the data int the database #res = cursor.execute(info["sql"]) #r = tuple(afterProcessArray) #sql = "UPDATE ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D SET RESTRT_SRVC_DTL_DN='%s' WHERE ESCLT_RESTRT_SRVC_TYPE_D_KY=%d"%(afterProcessArray[3],count) sql = "UPDATE ITR23.RLT_ESCLT_PRBLM_CI_RELSHP_F SET DATA_WHSE_UPD_TS= SYSDATE,CRC_CHCKSM_TX='%s' WHERE ESCLT_MGMT_D_KY= %d AND PRBLM_CI_D_KY = %d " % ( md5_str, afterProcessArray[0], afterProcessArray[1]) cursor.execute(sql) con.commit() else: res = RedisOp(["get", "RLT_ESCLT_PRBLM_CI_RELSHP_F_count"]) r_s = [] #count = 0 if res[0]: count = int(res[1]) + 1 RedisOp( ["set", "RLT_ESCLT_PRBLM_CI_RELSHP_F_count", count]) r_s.append(count) # inster data to the database #afterProcessArray.insert(0, count) afterProcessArray.append(count) r = tuple(afterProcessArray) RedisOp(["set", "Rs_RLT_ESCLT_PRBLM_CI_RELSHP_F", r]) sql_v = sql_inster % r RedisOp( ["set", "RLT_ESCLT_PRBLM_CI_RELSHP_F_sql_v", sql_v]) cursor.execute((sql_inster % r)) con.commit() else: RedisOp(["set", "RLT_ESCLT_PRBLM_CI_RELSHP_F_count", 1]) r_s.append(1) # inster data to the database #afterProcessArray.insert(0, 1) afterProcessArray.append(1) r = tuple(afterProcessArray) sql = sql_inster % r RedisOp(["set", "RLT_ESCLT_PRBLM_CI_RELSHP_F_sql_v", sql]) cursor.execute(sql) con.commit() r_s.append(md5_str) RedisOp(["set", dvc_id, r_s])
info = { "sql": sql_key, "username": "******", "passward": "4.!INFRitr2DEVpw_20160504", "host": "g1u2115.austin.hp.com", "port": "1525", "sid": "ITRD" } redis_key = 'HR_PERS_D.' + str(oracleOp(info)) sql_value = "SELECT EMP_KY AS EMP_KY,EMAIL_ADDR_NM AS EMAIL_ADDR_NM,EMP_TYPE_TX AS EMP_TYPE_TX,FULL_NM AS FULL_NM,SRC_SYS_KY AS SRC_SYS_KY, SRC_SYS_INSTNC_KY AS SRC_SYS_INSTNC_KY, \ EMP_STAT_IND AS EMP_STAT_IND,BUS_UNIT_NM AS BUS_UNIT_NM,BUS_ORG_CD AS BUS_ORG_CD,ORG_CHART_GRP_CD AS ORG_CHART_GRP_CD, BUS_SCTR_CD AS BUS_SCTR_CD \ FROM (SELECT ROW_NUMBER() OVER (PARTITION BY EMAIL_ADDR_NM ORDER BY EMP_STAT_IND, EMP_KY DESC) AS ROW_RANK, \ HR_PERS_D.EMAIL_ADDR_NM AS EMAIL_ADDR_NM,EMP_TYPE_TX AS EMP_TYPE_TX,FULL_NM AS FULL_NM,SRC_SYS_KY AS SRC_SYS_KY,SRC_SYS_INSTNC_KY AS SRC_SYS_INSTNC_KY, \ EMP_STAT_IND AS EMP_STAT_IND,BUS_UNIT_NM AS BUS_UNIT_NM,BUS_ORG_CD AS BUS_ORG_CD,ORG_CHART_GRP_CD AS ORG_CHART_GRP_CD,BUS_SCTR_CD AS BUS_SCTR_CD, EMP_KY \ FROM ITR23.HR_PERS_D) WHERE ROW_RANK=1 AND ROWNUM = " + line_no info = { "sql": sql_value, "username": "******", "passward": "4.!INFRitr2DEVpw_20160504", "host": "g1u2115.austin.hp.com", "port": "1525", "sid": "ITRD" } redis_value = oracleOp(info) RedisOp(['set', redis_key, redis_value])
def process_data(iterator): column = "ESCLT_ID,REC_NR,ESCLT_RESTRT_SRVC_TYPE_D_KY,ESCLT_MGMT_D_KY,MSTR_L_RESTRT_SRVC_TYPE_KY" value = "VALUES('%s',%d,%d,%d,%d)" sql_inster = "INSERT INTO ITR23.RLT_ESCLT_RESTRT_SRVC_DTL_F" + "(" + column + ")" + value dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] del oneTuple[3] checkDataMd5 = '' dvc_id = "RLT_ESCLT_RESTRT_SRVC_DTL_F" + str(oneTuple[0]) + str( oneTuple[1]) lkp_condition = "ESCLT_RESTRT_SRVC_TYPE_D" + str( oneTuple[0]) + str(oneTuple[1]) res = RedisOp(["get", lkp_condition]) if res[0]: r_s = list(eval(res[1])) oneTuple.append(int(r_s[0])) RedisOp(["set", "lkp_ESCLT_RESTRT_SRVC_DTL_F", r_s[0]]) else: oneTuple.append(0) #cursor.execute("SELECT DISTINCT ESCLT_RESTRT_SRVC_TYPE_D_KY FROM ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D WHERE ESCLT_ID='%s' AND REC_NR=%d" % (oneTuple[0], oneTuple[1])) #row = cursor.fetchone() #if row !=None: # oneTuple.append(row[0]) #else: # oneTuple.append(0) cursor.execute( "SELECT DISTINCT ESCLT_MGMT_D_KY FROM ITR23.ESCLT_D WHERE ESCLT_ID = '%s'" % oneTuple[0]) row = cursor.fetchone() if row != None: oneTuple.append(row[0]) else: oneTuple.append(0) if oneTuple[2] != None: cursor.execute( "SELECT DISTINCT HPSC_MSTR_L_KY from ITR23.HPSC_MSTR_L_CD_D where MSTR_L_COL_ID='ML_RSTAT_SEVC_TYPE_KY' and VALU_ID=%d" % oneTuple[2]) row = cursor.fetchone() if row != None: oneTuple.append(row[0]) else: oneTuple.append(0) else: oneTuple.append(-2) #oneTuple.append(oneTuple[2]) #delElement = [2] #Remove ML_RSTAT_SEVC_TYPE_KY,exits in L1(3th),do not needed in D #for i in delElement: del oneTuple[2] # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') # check if the md5 are the same or existence md5_str = hashlib.md5(checkDataMd5).hexdigest() #afterProcessArray.append(md5_str) operation = [] operation.append("get") operation.append(dvc_id) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str #RedisOp(["set", dvc_id, r_s]) RedisOp(["set", dvc_id, r_s]) res = RedisOp(["get", "RLT_ESCLT_RESTRT_SRVC_DTL_F_count"]) #count = int(res[1]) #afterProcessArray.insert(0, count) # update the data int the database #res = cursor.execute(info["sql"]) #r = tuple(afterProcessArray) #sql = "UPDATE ITR23.RLT_ESCLT_RESTRT_SRVC_TYPE_D SET RESTRT_SRVC_DTL_DN='%s' WHERE ESCLT_RESTRT_SRVC_TYPE_D_KY=%d"%(afterProcessArray[3],count) sql = "UPDATE ITR23.RLT_ESCLT_RESTRT_SRVC_DTL_F SET ESCLT_RESTRT_SRVC_TYPE_D_KY= %d,ESCLT_MGMT_D_KY=%d,MSTR_L_RESTRT_SRVC_TYPE_KY=%d WHERE ESCLT_ID= '%s' AND REC_NR = %d " % ( afterProcessArray[2], afterProcessArray[3], afterProcessArray[4], afterProcessArray[0], afterProcessArray[1]) cursor.execute(sql) con.commit() else: res = RedisOp(["get", "RLT_ESCLT_RESTRT_SRVC_DTL_F_count"]) r_s = [] #count = 0 if res[0]: count = int(res[1]) + 1 RedisOp( ["set", "RLT_ESCLT_RESTRT_SRVC_DTL_F_count", count]) r_s.append(count) # inster data to the database #afterProcessArray.insert(0, count) r = tuple(afterProcessArray) RedisOp(["set", "Rs_ESCLT_RESTRT_SRVC_DTL_F", r]) sql_v = sql_inster % r RedisOp(["set", "ESCLT_RESTRT_SRVC_DTL_F_sql_v", sql_v]) cursor.execute((sql_inster % r)) con.commit() else: RedisOp(["set", "RLT_ESCLT_RESTRT_SRVC_DTL_F_count", 1]) r_s.append(1) # inster data to the database #afterProcessArray.insert(0, 1) r = tuple(afterProcessArray) sql = sql_inster % r RedisOp(["set", "ESCLT_RESTRT_SRVC_DTL_F_sql_v", sql]) cursor.execute(sql) con.commit() r_s.append(md5_str) RedisOp(["set", dvc_id, r_s])
from redis_hash import RedisOp rs = RedisOp(["get", "CI_D"]) if rs[0]: rs = list(eval(rs[1])) for i in rs: key = "CI_D" + '.' + i[1] r = RedisOp(["set", key, i]) if r[0]: pass else: print("set faild")
def process_data(iterator): #column = "ESCLT_ACTN_ID,ESCLT_ID,ACTN_ID,ACTN_SUB_ID,ACTN_OWN_EMAIL_NM,MSTR_L_ESCLT_ACTN_STAT_KY,DUE_DT,ACTN_TX,SYS_MODF_DT,SYS_MODF_USER_NM,HP_CO_ID,SPRN_CO_ID" #values = "VALUES(%d,%s,%d,%d,%s,%d,NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),%s,,NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),%s,%s,%d)" #value = "VALUES(%d,%d,DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),%d,DECODE('%s','NULL',NULL),%d,%d,DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),NVL(TO_NUMBER(%s),NULL),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_DATE(DECODE('%s','NULL',NULL),'YYYY-MM-DD HH24:MI:SS'),null),DECODE('%s','NULL',NULL),DECODE('%s','NULL',NULL),NVL(TO_NUMBER(%s),NULL))" sql_insert = generateInsertSQL("ITR23.RLT_ESCLT_ACTN_D", "./RLT_ESCLT_ACTN_D.conf") dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] checkDataMd5 = '' actn_id = str(oneTuple[0]) # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: checkDataMd5 = checkDataMd5 + str(oneElement) afterProcessArray.append(oneElement) else: afterProcessArray.append('NULL') if oneElement != None: operation = ["get", "HPSC_MSTR_L_CD_D"] rs_mst = RedisOp(operation) one_res_mst = list(eval(rs_mst[1])) for i in one_res_mst: if afterProcessArray[5] in i: if i[6] == "ML_ESCLT_ACTN_STAT_KY": checkDataMd5 = checkDataMd5 + str(afterProcessArray[0]) afterProcessArray[5] = afterProcessArray[0] if i[0] == None: afterProcessArray[0] = 0 checkDataMd5 = checkDataMd5 + str( afterProcessArray[0]) elif afterProcessArray[5] == None: afterProcessArray[0] = -2 checkDataMd5 = checkDataMd5 + str( afterProcessArray[0]) operation = ["get", "HP_CO_TO_SPRN_CO_MAPG"] rs_sprn = RedisOp(operation) rs_sprn_list = list(eval(rs_sprn[1])) state = False for item in rs_sprn_list: if afterProcessArray[-1] in item: proData = item[1] checkDataMd5 = checkDataMd5 + str(proData) afterProcessArray.append(item[1]) state = True if not state: afterProcessArray.append(-2) checkDataMd5 = checkDataMd5 + str(afterProcessArray[-1]) md5_str = hashlib.md5(checkDataMd5).hexdigest() operation = [] operation.append("get") operation.append(actn_id) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str RedisOp(["set", actn_id, r_s]) #update the data int the database res = cursor.execute(info["sql"]) else: res = RedisOp(["get", "ESCLT_ACTN_D_count"]) r_s = [] if res[0]: count = int(res[1]) + 1 RedisOp(["set", "ESCLT_ACTN_D_count", count]) r_s.append(count) #inster data to the database afterProcessArray.insert(0, count) r = tuple(afterProcessArray) RedisOp(["set", "Rs", r]) sql_v = sql_inster % r RedisOp(["set", "sql_v", sql_v]) res = cursor.execute((sql_inster % r)) con.commit() else: RedisOp(["set", "ESCLT_ACTN_D_count", 1]) r_s.append(1) #inster data to the database afterProcessArray.insert(0, 1) r = tuple(afterProcessArray) sql = sql_inster % r RedisOp(["set", "sql_v", sql]) res = cursor.execute(sql) con.commit() r_s.append(md5_str) RedisOp(["set", actn_id, r_s])
def process_data(iterator): sql_insert = generateInsertSQL("ITR23.RLT_ESCLT_EVNT_D", "RLT_ESCLT_EVNT_D.conf") dsn = cx_Oracle.makedsn(info["host"], info["port"], info["sid"]) con = cx_Oracle.connect(info["username"], info["passward"], dsn) cursor = con.cursor() for oneArray in iterator: oneArray = list(eval(oneArray)) for i in range(len(oneArray)): afterProcessArray = [] oneTuple = oneArray[i] checkDataMd5 = '' sole_key = str(oneTuple[0]) # operating a tuple of a list for j in range(len(oneTuple)): oneElement = oneTuple[j] if oneElement != None: if type(oneElement) is str: proData = oneElement.strip() if j == 8 and proData == 'EVT': proData = 'EVERETT' if j == 8 and proData == 'STL': proData = 'SEATTLE' afterProcessArray.append(proData) checkDataMd5 = checkDataMd5 + proData else: afterProcessArray.append(oneElement) checkDataMd5 = checkDataMd5 + str(oneElement) else: afterProcessArray.append('NULL') #check if the md5 are the same or existence #Look up lookUpValue = RedisOp(['get', 'HP_CO_TO_SPRN_CO_MAPG']) lookUpList = list(eval(lookUpValue[1])) state = False for i in lookUpList: if afterProcessArray[-1] in i: afterProcessArray.append(i[1]) checkDataMd5 = checkDataMd5 + str(i[1]) state = True if not state: afterProcessArray.append(-2) md5_str = hashlib.md5(checkDataMd5).hexdigest() sole_key = 'RLT_ESCLT_EVNT_D' + sole_key operation = [] operation.append("get") operation.append(sole_key) rs = RedisOp(operation) if rs[0]: r_s = list(eval(rs[1])) if r_s[1] != md5_str: r_s[1] = md5_str afterProcessArray.insert(0, r_s[1]) r = tuple(afterProcessArray) #update the data int the database update_sql = generateUpdateSql("ITR23.RLT_ESCLT_EVNT_D", "RLT_ESCLT_EVNT_D.conf", ["ESCLT_EVNT_D_KY", r_s[0]]) res = cursor.execute(update_sql % r) con.commit() RedisOp(["set", sole_key, r_s]) else: res = RedisOp(["get", "ESCLT_EVNT_D_count"]) r_s = [] if res[0]: count = int(res[1]) + 1 r_s.append(count) #inster data to the database afterProcessArray.insert(0, count) r = tuple(afterProcessArray) sql_v = sql_insert % r res = cursor.execute((sql_insert % r)) con.commit() RedisOp(["set", "ESCLT_EVNT_D_count", count]) else: r_s.append(1) #inster data to the database afterProcessArray.insert(0, 1) r = tuple(afterProcessArray) sql = sql_insert % r res = cursor.execute(sql) con.commit() RedisOp(["set", "ESCLT_EVNT_D_count", 1]) r_s.append(md5_str) RedisOp(["set", sole_key, r_s])