优化日志管理
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
功能:将mysql从源数据表同步目标数据表 主要用于ocr 识别及自动脱敏程序
|
||||
"""
|
||||
import configparser
|
||||
import logging
|
||||
#import sys
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
# from tkinter import EXCEPTION
|
||||
import requests
|
||||
import json
|
||||
@@ -149,14 +152,14 @@ def sync_dbtarget(source_cursor,source_conn,target_cursor,target_db,i_sync_fiel
|
||||
target_db.commit()
|
||||
except Exception as e:
|
||||
target_db.rollback()
|
||||
print('插入失败imp_'+i_table_name+",原因"+str(e))
|
||||
logging.error('插入失败imp_'+i_table_name+",原因"+str(e))
|
||||
continue
|
||||
sql = ""
|
||||
j = j + 1
|
||||
# 每一千条打印
|
||||
if divmod(j, 1000)[1] == 0:
|
||||
print("已经插入"+i_imp_table_name+":" +str(j) + "条")
|
||||
print("插入"+i_imp_table_name+":" + str(j - 1) + "条")
|
||||
logging.info("已经插入"+i_imp_table_name+":" +str(j) + "条")
|
||||
logging.info("插入"+i_imp_table_name+":" + str(j - 1) + "条")
|
||||
if v_pk_phhd[1:] != '':
|
||||
v_sql ='';
|
||||
v_mess='';
|
||||
@@ -182,10 +185,10 @@ def sync_dbtarget(source_cursor,source_conn,target_cursor,target_db,i_sync_fiel
|
||||
try:
|
||||
source_cursor.execute(v_sql)
|
||||
source_conn.commit()
|
||||
print(v_mess+'成功!'+' from:'+i_table_name+' ,to:'+i_imp_table_name)
|
||||
logging.info(v_mess+'成功!'+' from:'+i_table_name+' ,to:'+i_imp_table_name)
|
||||
except Exception as e:
|
||||
source_conn.rollback()
|
||||
print(v_mess+"失败,原因"+str(e))
|
||||
logging.error(v_mess+"失败,原因"+str(e))
|
||||
|
||||
def main():
|
||||
# path = os.path.abspath(os.path.dirname(__file__))
|
||||
@@ -297,7 +300,7 @@ def main():
|
||||
target_conn.commit
|
||||
except Exception as e:
|
||||
target_conn.rollback()
|
||||
print("删除目标表失败"+"imp_开头表,原因"+str(e))
|
||||
logging.error("删除目标表失败"+"imp_开头表,原因"+str(e))
|
||||
|
||||
source_cursor = source_conn.cursor()
|
||||
try:
|
||||
@@ -312,7 +315,7 @@ def main():
|
||||
source_conn.commit
|
||||
except Exception as e:
|
||||
source_conn.rollback()
|
||||
print("删除源表失败"+"imp_开头表,原因"+str(e))
|
||||
logging.error("删除源表失败"+"imp_开头表,原因"+str(e))
|
||||
|
||||
|
||||
#v_sql ="select date_format(date_sub(max(sync_date),interval 1 day) , '%Y-%m-%d') pk_maxvalue from wzx2017.sys_sybnc_date"
|
||||
@@ -350,14 +353,14 @@ def main():
|
||||
v_title = "花费{mtime:.0f}分{stime:.0f}秒时间,同步成功!".format(
|
||||
mtime=time_elapsed // 60,
|
||||
stime=time_elapsed % 60)
|
||||
print(v_title)
|
||||
logging.info(v_title)
|
||||
|
||||
v_sql = 'insert into sys_sync_date(sync_date,sync_direct,depiction) values(CURRENT_TIMESTAMP,"1","{}") '.format(v_title)
|
||||
try:
|
||||
target_cursor.execute(v_sql)
|
||||
target_conn.commit()
|
||||
except Exception as e:
|
||||
print('追加记录至sys_sybnc_date失败?' + ",原因" + str(e))
|
||||
logging.error('追加记录至sys_sybnc_date失败?' + ",原因" + str(e))
|
||||
target_conn.rollback()
|
||||
|
||||
v_sql = 'call pro_sync_waitfor_ocrdata(1,@dd);'
|
||||
@@ -365,7 +368,7 @@ def main():
|
||||
target_cursor.execute(v_sql)
|
||||
target_conn.commit()
|
||||
except Exception as e:
|
||||
print('同步至待ocr 识别完成失败(pro_sync_waitfor_ocrdata)?' + ",原因" + str(e))
|
||||
logging.error('同步至待ocr 识别完成失败(pro_sync_waitfor_ocrdata)?' + ",原因" + str(e))
|
||||
target_conn.rollback()
|
||||
|
||||
v_sql = 'select * from sys_sync_tables where sync_direct="2" and del_flag=0 order by 1 '
|
||||
@@ -393,14 +396,14 @@ def main():
|
||||
v_title = "花费{mtime:.0f}分{stime:.0f}秒时间,同步成功!".format(
|
||||
mtime=time_elapsed // 60,
|
||||
stime=time_elapsed % 60)
|
||||
print(v_title)
|
||||
logging.info(v_title)
|
||||
|
||||
v_sql = 'insert into sys_sync_date(sync_date,sync_direct,depiction) values(CURRENT_TIMESTAMP,"2","{}") '.format(v_title)
|
||||
try:
|
||||
target_cursor.execute(v_sql)
|
||||
target_conn.commit()
|
||||
except Exception as e:
|
||||
print('追加记录至sys_sybnc_date失败?' + ",原因" + str(e))
|
||||
logging.error('追加记录至sys_sybnc_date失败?' + ",原因" + str(e))
|
||||
target_conn.rollback()
|
||||
|
||||
v_sql = 'call pro_photoocr_update(1,@dd);'
|
||||
@@ -408,7 +411,7 @@ def main():
|
||||
source_cursor.execute(v_sql)
|
||||
source_conn.commit()
|
||||
except Exception as e:
|
||||
print('ocr识别结果同步完成失败(pro_photoocr_update)?' + ",原因" + str(e))
|
||||
logging.error('ocr识别结果同步完成失败(pro_photoocr_update)?' + ",原因" + str(e))
|
||||
source_conn.rollback()
|
||||
|
||||
v_sql = "select a.pk_phhd from imp_zx_phapply a left join zx_phhd b on a.pk_phhd=b.pk_phhd where a.cStatus='2' and b.pk_phhd is null;"
|
||||
@@ -427,7 +430,7 @@ def main():
|
||||
source_conn.commit()
|
||||
except Exception as e:
|
||||
v_error='(存在待ocr识别但没有成功的案子,自动处理失败' + ",原因" + str(e)+')'
|
||||
print(v_error)
|
||||
logging.error(v_error)
|
||||
source_conn.rollback()
|
||||
|
||||
v_sql = "select count(1) jl from zx_phhd where paint_flag in ('1','2');"
|
||||
@@ -456,7 +459,11 @@ def main():
|
||||
)
|
||||
# v_head=v_mess+v_head
|
||||
## 定义上午11点和中午12点的时间对象
|
||||
v_hour=time.strftime("%H", time.localtime(time.time()))
|
||||
if ('09'<=v_hour<'10' or '17'<=v_hour<'18') or v_paint>300 :
|
||||
now = datetime.now()
|
||||
v_hour = now.hour
|
||||
v_minute = now.minute
|
||||
if ((v_hour == 8 and 30 <= v_minute < 45)
|
||||
or (v_hour == 11 and 0 <= v_minute < 15)
|
||||
or (v_hour == 17 and 0 <= v_minute < 15)) or v_paint>300 :
|
||||
send_data(html_msg, v_head,v_paint)
|
||||
# os._exit(0)
|
||||
Reference in New Issue
Block a user