def file_check(phoneNumList,role_name): try: dblist = connectDb.getConnectInfo() dbconn = connectDb.connectDb(dblist[0]) cursor = dbconn.cursor() cursor.execute(sql) log_tables=cursor.fetchall() log_list = [] for log_table in log_tables: cursor.execute(check_sql % (log_table)) check_result=cursor.fetchall() check_list=[] for x in check_result: y=x[0].split("/") check_list.append(y[2]) check_list=set(check_list) if (len(check_list) <= 1): #print "S" pass else: #生成短信告警信息 log_list.append('check_time:%s,bill.%s be exception: %s, please check!!!!'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),log_table,check_list)) cursor.close() connectDb.closeConnect(dbconn) #是否发短信 if (len(log_list) < 1): pass else: #短信发送 message.message_send(log_list,phoneNumList) except Exception,e: with open(r'error.log','a') as error_log: print >> error_log,('%s %s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),' Excute ft_info_data SQL Faild:',e))
def insertToDatabase(id, name, url, date, updated, price, where): global last_insert cnxn = connectDb() cursor = cnxn.cursor() rows = cursor.execute( "SELECT post_id from listings order by tstmp desc").fetchall() results = [row[0] for row in rows] #print(results) try: if id not in results: Logger.writeAndPrintLine('Adding ' + id + ' to database...', 0) cursor.execute( "insert into listings (post_id, timestamp, url, subject, price, location, tstmp) values (" + id + ", '" + date + "', '" + url + "', '" + name + "', '" + price + "', '" + where + "', (current_timestamp));") cursor.commit() Logger.writeLine('done.', 0) last_insert = id Logger.writeAndPrintLine('Posting ' + id + ' to Slack...', 0) slacklist = [date, name, price, where, url] slackmsg = str(slacklist) postToSlack(slackmsg) Logger.writeLine('done.', 0) except: Logger.writeAndPrintLine( 'Error inserting ID ' + id + ' into database.', 0) pass cursor.close() disconnectDb(cnxn)
def dealSql(): try: dblist = connectDb.getConnectInfo() #VOP库连接 dbconn = connectDb.connectDb(dblist[0]) dbconncr = dbconn.cursor() #业务类型为12(告警类) dbconncr.execute("select * from monitor.t_mot_conf a where a.business_type = '12' and not exists(select 1 from monitor.t_mot_noacq_plan t where t.acq_bg_time < to_char(sysdate,'hh24miss') and t.acq_ed_time > to_char(sysdate,'hh24miss') and a.m_id = t.m_id)") result = dbconncr.fetchall() for confArray in result: #要执行的SQL是预警类 if confArray[9] == '1': if confArray[2] in ["SQL00", "SQL01"]: sql0(confArray[1], dbconncr, confArray[4], confArray[7], confArray[0], confArray[2], confArray[3], confArray[5], dbconn) elif confArray[2] in ["SQL10", "SQL11"]: startTimeInterValList = getTimeInterval.getInterVal(confArray[5], dbconncr) for startTimeIndex in range(len(startTimeInterValList)): sql1(confArray[1], dbconncr, startTimeInterValList[startTimeIndex][0], confArray[5], confArray[4], confArray[0], confArray[7], confArray[2], confArray[3], startTimeInterValList[startTimeIndex][1], dbconn) else: with open(r'error.log','a') as error_log: print >> error_log,('%s %s $s' % (time.ctime(), "'M_ID:'" + confArray[0], 'SQL Tpye Error:')) #信息采集 else: if confArray[2] == "SQL1": startTimeInterValList = getTimeInterval.getInterVal(confArray[5], dbconncr) for startTimeIndex in range(len(startTimeInterValList)): dealCollectInfo.sql1(confArray[1], dbconncr, startTimeInterValList[startTimeIndex][0], confArray[5], confArray[0], startTimeInterValList[startTimeIndex][1], dbconn) connectDb.closeConnect(dbconn) except Exception,e: with open(r'error.log','a') as error_log: print >> error_log,('%s %s %s' % (time.ctime(),'Deal Data Faild:',e))
def dealSql(): try: dblist = connectDb.getConnectInfo() dbconn = connectDb.connectDb(dblist) dbconncr = dbconn.cursor() #业务类型为1、2、6、7(告警类) 3、8(采集类) dbconncr.execute("select * from monitor.t_mot_conf a where a.business_type in('1','2','6','7','3','8','13')") #dbconncr.execute("select * from monitor.t_mot_conf a where a.business_type in('2')") result = dbconncr.fetchall() for confArray in result: #要执行的SQL是预警类 if confArray[9] == '1': if confArray[2] in ["SQL00", "SQL01"]: sql0(confArray[1], dbconncr, confArray[4], confArray[7], confArray[0], confArray[2], confArray[3]) elif confArray[2] in ["SQL10", "SQL11"]: startTimeInterValList = getTimeInterval.getInterVal(confArray[5], dbconncr) for startTimeIndex in range(len(startTimeInterValList)): sql1(confArray[1], dbconncr, startTimeInterValList[startTimeIndex][0], confArray[5], confArray[4], confArray[0], confArray[7], confArray[2], confArray[3], startTimeInterValList[startTimeIndex][1], dbconn) else: with open(r'error.log','a') as error_log: print >> error_log,('%s %s $s' % (time.ctime(), "'M_ID:'" + confArray[0], 'SQL Tpye Error:')) #信息采集 else: if confArray[2] == "SQL1": startTimeInterValList = getTimeInterval.getInterVal(confArray[5], dbconncr) for startTimeIndex in range(len(startTimeInterValList)): dealCollectInfo.sql1(confArray[1], dbconncr, startTimeInterValList[startTimeIndex][0], confArray[5], confArray[0], startTimeInterValList[startTimeIndex][1], dbconn) connectDb.closeConnect(dbconn) except Exception,e: with open(r'error.log','a') as error_log: print >> error_log,('%s %s %s' % (time.ctime(),'Deal Data Faild:',e))
def execParity(parity): try: if parity == 'ODD': parity1='ODD' parity2='EVEN' else: parity2='ODD' parity1='EVEN' Parity_sqllist=["insert into BILLING.ERR_FORMAT_STRM_BAK_%s (file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouser1 ,nouser2 ,file_id ,cdr_file_name ,nouser3 ,nouser4 ,nouser5 ,exception_file_id ,exception_cdr_id ,local_net ,nouser6 ,exception_type ,record_type ,self_number ,start_time ,end_time ,duration ,nouser7 ,fee_stream ,nouser8 ,service_id ,up_vol1 ,down_vol1 ,nouser9 ,nouser10 ,imsi ,imei ,self_lac_id ,self_cell_id ,nouser11 ,nouser12 ,nouser13 ,nouser14 ,nouser15 ,nouser16 ,sgsn_addr ,ggsn_addr ,network_init ,charging_id ,pdp_type ,nouser17 ,nouser18 ,sfee ,tfee ,nouser19 ,nouser20 ,ms_nc ,nouser21 ,nouser22 ,nouser23 ,apn_ni ,nouser24 ,apn_oi ,sgsn_change ,plmn_id ,nouser25 ,user_type ,sevice_class ,close_cause ,nouser26 ,nouser27 ,rat_type ,nouser28 ,nouser29 ,nouser30 ,user_id ,nouser31 ,nouser32 ,nas_ip ,ap_ssid ,ocs_info ,connection_id ,csg_info ,pdp_addr ,nouser33 ,nouser34 ,nouser35 ,nouser36 ,nouser37 ,nouser38 ,nouser39 ,nouser40 ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,redo_mark ,src_record ,record_serial ,redo_flag,ERR_BAKTIME,ERR_BAKMONTH,ERR_BAKDAY) select file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouser1 ,nouser2 ,file_id ,cdr_file_name ,nouser3 ,nouser4 ,nouser5 ,exception_file_id ,exception_cdr_id ,local_net ,nouser6 ,exception_type ,record_type ,self_number ,start_time ,end_time ,duration ,nouser7 ,fee_stream ,nouser8 ,service_id ,up_vol1 ,down_vol1 ,nouser9 ,nouser10 ,imsi ,imei ,self_lac_id ,self_cell_id ,nouser11 ,nouser12 ,nouser13 ,nouser14 ,nouser15 ,nouser16 ,sgsn_addr ,ggsn_addr ,network_init ,charging_id ,pdp_type ,nouser17 ,nouser18 ,sfee ,tfee ,nouser19 ,nouser20 ,ms_nc ,nouser21 ,nouser22 ,nouser23 ,apn_ni ,nouser24 ,apn_oi ,sgsn_change ,plmn_id ,nouser25 ,user_type ,sevice_class ,close_cause ,nouser26 ,nouser27 ,rat_type ,nouser28 ,nouser29 ,nouser30 ,user_id ,nouser31 ,nouser32 ,nas_ip ,ap_ssid ,ocs_info ,connection_id ,csg_info ,pdp_addr ,nouser33 ,nouser34 ,nouser35 ,nouser36 ,nouser37 ,nouser38 ,nouser39 ,nouser40 ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,redo_mark ,src_record ,record_serial ,redo_flag,SYSDATE,TO_CHAR(SYSDATE,'mm'),TO_CHAR(SYSDATE,'dd') FROM BILLING.ERR_FORMAT_STRM where redo_flag = 1" % parity1,"insert into BILLING.ERR_FORMAT_MBVC_BAK_%s (file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouse1 ,nouse2 ,file_id ,org_file_name ,nouse3 ,nouse4 ,nouse5 ,exception_file_id ,exception_cdr_id ,local_net ,nouse6 ,exception_type ,record_type ,org_area_code ,org_number ,nouse7 ,trim_area_code ,trim_number ,nouse8 ,third_number ,nouse9 ,self_number ,nouse10 ,start_time ,end_time ,duration ,imsi ,imei ,nouse11 ,roam_area_code ,roam_type ,self_lac_id ,self_cell_id ,in_trunk ,out_trunk ,tfee ,nouse12 ,nouse13 ,nouse14 ,nouse15 ,nouse16 ,nouse17 ,merge_flag ,nouse18 ,nouse19 ,nouse20 ,free_flag ,user_type ,long_type ,msc ,self_msc ,net_type ,nouse21 ,nouse22 ,turn_type ,nouse24 ,video_flag ,third_flag ,nouse25 ,nouse26 ,nouse27 ,bearer_service ,nouse28 ,nouse29 ,nouse30 ,pay_flag ,org_vpn_code ,org_subvpn_code ,org_scp_code ,trim_vpn_code ,trim_subvpn_code ,trim_scp_code ,closed_group_number ,gourp_number ,subtype ,nouse31 ,dm_flag ,nouse32 ,nouse33 ,nouse34 ,nouse35 ,nouse36 ,nouse37 ,nouse38 ,nouse39 ,nouse40 ,nouse41 ,nouse42 ,opp_lac_id ,opp_cell_id ,nouse43 ,nouse44 ,nouse45 ,nouse46 ,plmn ,reserve ,redo_mark ,src_record ,record_serial ,redo_flag,ERR_BAKTIME,ERR_BAKMONTH,ERR_BAKDAY) select file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouse1 ,nouse2 ,file_id ,org_file_name ,nouse3 ,nouse4 ,nouse5 ,exception_file_id ,exception_cdr_id ,local_net ,nouse6 ,exception_type ,record_type ,org_area_code ,org_number ,nouse7 ,trim_area_code ,trim_number ,nouse8 ,third_number ,nouse9 ,self_number ,nouse10 ,start_time ,end_time ,duration ,imsi ,imei ,nouse11 ,roam_area_code ,roam_type ,self_lac_id ,self_cell_id ,in_trunk ,out_trunk ,tfee ,nouse12 ,nouse13 ,nouse14 ,nouse15 ,nouse16 ,nouse17 ,merge_flag ,nouse18 ,nouse19 ,nouse20 ,free_flag ,user_type ,long_type ,msc ,self_msc ,net_type ,nouse21 ,nouse22 ,turn_type ,nouse24 ,video_flag ,third_flag ,nouse25 ,nouse26 ,nouse27 ,bearer_service ,nouse28 ,nouse29 ,nouse30 ,pay_flag ,org_vpn_code ,org_subvpn_code ,org_scp_code ,trim_vpn_code ,trim_subvpn_code ,trim_scp_code ,closed_group_number ,gourp_number ,subtype ,nouse31 ,dm_flag ,nouse32 ,nouse33 ,nouse34 ,nouse35 ,nouse36 ,nouse37 ,nouse38 ,nouse39 ,nouse40 ,nouse41 ,nouse42 ,opp_lac_id ,opp_cell_id ,nouse43 ,nouse44 ,nouse45 ,nouse46 ,plmn ,reserve ,redo_mark ,src_record ,record_serial ,redo_flag,SYSDATE,TO_CHAR(SYSDATE,'mm'),TO_CHAR(SYSDATE,'dd') FROM BILLING.ERR_FORMAT_MBVC where redo_flag = 1" % parity1,"insert into BILLING.ERR_FORMAT_SMSG_BAK_%s (file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouser1 ,nouser2 ,file_id ,cdr_file_name ,nouser3 ,nouser4 ,nouser5 ,exception_file_id ,exception_cdr_id ,local_net ,nouser6 ,exception_type ,record_type ,org_number ,trim_number ,nouser8 ,start_time ,end_time ,nouser9 ,imsi ,imei ,nouser10 ,ifee ,mfee ,gfee ,nouser11 ,nouser12 ,nouser13 ,sms_length ,nouser14 ,sp_code ,nouser15 ,nouser16 ,access_code ,service_code ,nouser17 ,smg_code ,forw_smg_code ,agency_flag ,send_status ,sms_code ,nouser18 ,nouser19 ,nouser20 ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,redo_mark ,src_record ,record_serial ,redo_flag,ERR_BAKTIME,ERR_BAKMONTH,ERR_BAKDAY) select file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouser1 ,nouser2 ,file_id ,cdr_file_name ,nouser3 ,nouser4 ,nouser5 ,exception_file_id ,exception_cdr_id ,local_net ,nouser6 ,exception_type ,record_type ,org_number ,trim_number ,nouser8 ,start_time ,end_time ,nouser9 ,imsi ,imei ,nouser10 ,ifee ,mfee ,gfee ,nouser11 ,nouser12 ,nouser13 ,sms_length ,nouser14 ,sp_code ,nouser15 ,nouser16 ,access_code ,service_code ,nouser17 ,smg_code ,forw_smg_code ,agency_flag ,send_status ,sms_code ,nouser18 ,nouser19 ,nouser20 ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,redo_mark ,src_record ,record_serial ,redo_flag,SYSDATE,TO_CHAR(SYSDATE,'mm'),TO_CHAR(SYSDATE,'dd') FROM BILLING.ERR_FORMAT_SMSG where redo_flag = 1" % parity1,"insert into BILLING.ERR_FORMAT_VACP_BAK_%s (file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouse1 ,nouse2 ,file_id ,src_file_name ,cdr_id ,nouse3 ,nouse4 ,nouse5 ,nouse6 ,nouse7 ,nouse8 ,nouse9 ,org_number ,trm_number ,nouse10 ,start_time ,end_time ,duration ,up_vol ,down_vol ,ifee ,sequence ,nouse11 ,sp_id ,service_id ,cp_id ,content_id ,product_neti ,mobile_type ,nouse23 ,mobile_no ,vac_serv_type ,product_id ,sub_product ,sp_product ,nouse13 ,nouse14 ,nouse15 ,pay_flag ,fee_point ,user_pay_typ ,nouse24 ,imsi ,nouse25 ,nouse16 ,nouse17 ,nouse18 ,nouse19 ,nouse20 ,nouse21 ,record_type ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,nouse22 ,reserve6 ,redo_mark ,src_record ,record_serial ,redo_flag ,ERR_BAKTIME,ERR_BAKMONTH,ERR_BAKDAY) select file_name ,file_sn ,thread_id ,error_code ,error_pos ,cdr_type ,nouse1 ,nouse2 ,file_id ,src_file_name ,cdr_id ,nouse3 ,nouse4 ,nouse5 ,nouse6 ,nouse7 ,nouse8 ,nouse9 ,org_number ,trm_number ,nouse10 ,start_time ,end_time ,duration ,up_vol ,down_vol ,ifee ,sequence ,nouse11 ,sp_id ,service_id ,cp_id ,content_id ,product_neti ,mobile_type ,nouse23 ,mobile_no ,vac_serv_type ,product_id ,sub_product ,sp_product ,nouse13 ,nouse14 ,nouse15 ,pay_flag ,fee_point ,user_pay_typ ,nouse24 ,imsi ,nouse25 ,nouse16 ,nouse17 ,nouse18 ,nouse19 ,nouse20 ,nouse21 ,record_type ,reserve1 ,reserve2 ,reserve3 ,reserve4 ,reserve5 ,nouse22 ,reserve6 ,redo_mark ,src_record ,record_serial ,redo_flag ,SYSDATE,TO_CHAR(SYSDATE,'mm'),TO_CHAR(SYSDATE,'dd') FROM BILLING.ERR_FORMAT_VACP where redo_flag = 1" % parity1] Truncate_sqllist=["alter table BILLING.ERR_FORMAT_STRM_BAK_%s truncate partition ERR_STRM_%s_%s update global indexes" % (parity2,parity2,day),"alter table BILLING.ERR_FORMAT_MBVC_BAK_%s truncate partition ERR_MBVC_%s_%s update global indexes" % (parity2,parity2,day),"alter table BILLING.ERR_FORMAT_SMSG_BAK_%s truncate partition ERR_SMSG_%s_%s update global indexes" % (parity2,parity2,day),"alter table BILLING.ERR_FORMAT_VACP_BAK_%s truncate partition ERR_VACP_%s_%s update global indexes" % (parity2,parity2,day)] sqllist=zip(Parity_sqllist,Truncate_sqllist) filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) for sql in sqllist: insert_result=connectDb.executeSQL(cursor,sql[0]) if insert_result == True: truncate_result=connectDb.executeSQL(cursor,sql[1]) connectDb.sqlcommit(dbconn) except Exception,e: parityerr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute parity falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(parityerr,e))
def insertlog(phoneNumList,role_name,M_INTERVAL): try: dblist = connectDb.getConnectInfo() #VOP库连接 dbconn = connectDb.connectDb(dblist[0]) dbconncr = dbconn.cursor() if compareExecTime.compareExecTime(M_INTERVAL,role_name,dbconncr) == True : # print "开始执行命令" dbconncr.execute("select monitor.billpro_fk_idseq.nextval from dual") result = dbconncr.fetchall() SEQ_FK = result[0][0] #采集数统计 rstlist = runCmd.runcmd("zhcjprod") cjcount = 0 for result in rstlist: #print result cjcount += int(result.split(";")[1]) rstlistA = runCmd.runcmd("acquire_A") rstlistB = runCmd.runcmd("acquire_B") acquirelist = rstlistA + rstlistB #分发数统计并入表 for acquire in acquirelist: mvno = acquire.split(";")[0].split("/")[5] prod = acquire.split(";")[0].split("/")[6] count = int(acquire.split(";")[1]) # print 'MVNO:%s,PROD:%s,COUNT:%s'%(mvno,prod,count) dbconncr.execute("insert into monitor.i_mv_billpro(MVNO, PROD, FILE_COUNT, INSERT_TIME, FLAG,SEQ_FK) values ('" + str(mvno) + "','" + str(prod) +"','" + str(count) + "',sysdate,'0','" + str(SEQ_FK) +"')") dbconncr.execute("insert into monitor.t_mot_billpro_log(BILLPRO_ID, CJFILE_COUNT, MVNO, YY_COUNT, SJ_COUNT, DX_COUNT, ZZ_COUNT, INSERT_TIME, SEQ_FK, FLAG) select monitor.billpro_idseq.nextval,'" + str(cjcount) + "',mvno,YY,SJ,DX,ZZ,sysdate,'" + str(SEQ_FK) +"','0' from (select mvno,sum(decode(prod,'YY',file_count,0)) YY,sum(decode(prod,'SJ',file_count,0)) SJ,sum(decode(prod,'DX',file_count,0)) DX,sum(decode(prod,'ZZ',file_count,0)) ZZ from monitor.i_mv_billpro where flag = '0' and SEQ_FK = '" + str(SEQ_FK) +"' group by mvno)") dbconncr.execute("delete from monitor.i_mv_billpro where flag = '0' and seq_fk = '"+ str(SEQ_FK) +"'") #入短信表 for phoneNum in phoneNumList: dbconncr.execute("""insert into monitor.sms_send_routine (SMS_ID, TEL_NUM, ROLE_NAME, CONTENT, STATUS, INSERT_TIME, SEND_TIME) select monitor.sms_send_routine_pk_seq.nextval,'""" + str(phoneNum) + """','bill_infor',CONTENT, '0', sysdate, null from (select sum(t.cjfile_count)/count(1) || '个文件未采集,话单分发-情况:'||to_char(wm_concat('【' || mb.mvno_business_name || ':YY'|| t.yy_count ||',DX'|| t.dx_count ||',SJ'||t.sj_count || '】')) CONTENT from monitor.t_mot_billpro_log t,dbvop.mvno_business mb where t.mvno = mb.mvno_business_mark and t.flag = '0' and t.seq_fk = '"""+ str(SEQ_FK) +"""' group by t.seq_fk)""") dbconncr.execute("update monitor.t_mot_billpro_log set flag = '2' where flag = '0' and seq_fk = '"+ str(SEQ_FK) +"'") dbconn.commit() dbconncr.close() connectDb.closeConnect(dbconn) else: dbconncr.close() connectDb.closeConnect(dbconn) except Exception,e: dbconn.rollback() dbconncr.close() connectDb.closeConnect(dbconn) with open(r'error.log','a') as error_log: print >> error_log,('%s insertlog Faild: %s'%(time.ctime(),e)) log_tables = [] log_tables.append('%s insertlog Faild: %s'%(time.ctime(),e)) message.message_send(log_tables,phoneList)
def exeProcedure(sql): #try: filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) connectDb.executeSQL(cursor,sql) Res=connectDb.getSQLrst(cursor) connectDb.closeCursor(cursor) connectDb.closeConnect(dbconn) print Res return Res
def getSqlData(sql): try: filename='./config/billdbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) connectDb.executeSQL(cursor,sql) result=connectDb.getSQLrst(cursor) return result except Exception,e: getDataerr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute getSqlData falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(getDataerr,e))
def executeCount(sql): try: filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) connectDb.executeSQL(cursor,sql) result=connectDb.getSQLrst(cursor) query_result=result[0][0] #print query_result,type(query_result) return query_result except Exception,e: count_err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'executeCount falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(count_err,e)) return query_err
def getSqlRes(sql): try: filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) connectDb.executeSQL(cursor,sql) cols=[] for col in cursor.description: cols.append(col[0]) #print cols result=connectDb.getSQLrst(cursor) reslist=[] for res in result: reslist.append(list(res)) return (cols,reslist) except Exception,e: getReserr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute getSqlRes falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(getReserr,e))
def get_dbInfo(sql): try: filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) connectDb.executeSQL(cursor,sql) result=connectDb.getSQLrst(cursor) infodict={} for res in result: if infodict.has_key(res[0]): infodict[res[0]].append(res[1:]) else: infodict[res[0]]=[res[1:]] #print infodict return infodict except Exception,e: geterr='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute get_dbInfo falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(geterr,e))
def executeCommitsql(sqllist): try: reslist=[] filename='./config/dbinfo.ini' dblist=connectDb.getConnectInfo(filename) dbconn=connectDb.connectDb(dblist[0]) cursor=connectDb.getCursor(dbconn) for sql in sqllist: connectDb.executeSQL(cursor,sql) rowsaffected = cursor.rowcount reslist.append(rowsaffected) connectDb.sqlcommit(dbconn) update_result=sum(reslist) #print reslist #print update_result,type(update_result) return update_result except Exception,e: update_err='%s %s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'execute executeCommitsql falied') with open(r'./log/error.log','a') as error_log: print >> error_log,('%s %s' %(update_err,e)) return update_err
def dealBusiness(nb): dblist = connectDb.getConnectInfo("dbConnect") if type(dblist) is str: return dblist print str(nb) + "线程开始:" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') dbconn = connectDb.connectDb(dblist[0]) if type(dbconn) is str: print dbconn return dbconn cursor = connectDb.getCursor(dbconn) if type(cursor) is str: connectDb.closeConnect(dbconn) print cursor return cursor time.sleep(nb) print str(nb) + "线程程序处理结束:" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') connectDb.sqlcommit(dbconn) clsCor = connectDb.closeCursor(cursor) clsCnt = connectDb.closeConnect(dbconn) print "关闭连接:" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') if type(clsCor) is str: print clsCor if type(clsCnt) is str: print clsCnt