1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| import os import sys import datetime import time import pymysql
runDate = sys.argv[1]
evtResList={'EVT_001': 'N', 'EVT_002': 'N', 'EVT_003': 'N', 'EVT_004': 'N'}
try: conn_moia = pymysql.connect(host='199.188.166.110', port=3306, user='moia5', password='moia5', db='moia5', charset="utf8") cursor_moia = conn_moia.cursor() except Exception as e: print('数据库链接错误', e) exit(1) for key, value in evtResList.items(): try: sql_evt_judge = '''select count(*) from t04_evt_glob_info where evt_name='%s' ''' % key cursor_moia.execute(sql_evt_judge) conn_moia.commit() except Exception as e: print('数据库操作失败', e) exit(2) res_sql_evt_judge = cursor_moia.fetchall() for item in res_sql_evt_judge: if item[0] != 1: print("事件在moia中不存在, 默认失败:",key) sys.stdout.flush() evtResList[key]='F' try: cursor_moia.close() conn_moia.close() except Exception as e: print('数据库关闭失败:', e) exit(3)
evtNo=[] for key, value in evtResList.items(): if value == 'N': evtNo.append(key)
while 1==1: noList = "','".join(evtNo) try: conn_send_list = pymysql.connect(host='199.188.166.110', port=3306, user='moia5', password='moia5', db='zhaoty', charset="utf8") cursor_send_list = conn_send_list.cursor() except Exception as e: print('数据库链接错误', e) exit(1) try: sql_send_list = '''select name,date from zhaoty_test where state='1' and date='%s' and name in ('%s') ''' % (runDate,noList) cursor_send_list.execute(sql_send_list) conn_send_list.commit() except Exception as e: print('数据库操作失败', e) exit(2) try: cursor_send_list.close() conn_send_list.close() except Exception as e: print('数据库关闭失败:', e) exit(3)
try: conn_moia = pymysql.connect(host='199.188.166.110', port=3306, user='moia5', password='moia5', db='moia5', charset="utf8") cursor_moia = conn_moia.cursor() except Exception as e: print('数据库链接错误', e) exit(1) res_send_list = cursor_send_list.fetchall() print("本次循环有 %s 个事件满足发送条件, 需要发送至MOIA" % len(res_send_list)) for each in res_send_list: evt_name=each[0] evt_date=each[1] print("事件名称:",each[0],"事件日期:",each[1]) val = os.system('echo "22229061|{evt_name}|{evt_date}|00000|1"|ncat 199.188.166.110 57501'.format(evt_name=evt_name,evt_date=evt_date)) sys.stdout.flush() sql_evt_stat = '''select count(*) -- evt_info.evt_name,evt_stat.evt_date from t04_evt_src_stat evt_stat,t04_evt_glob_info evt_info where evt_stat.evt_id=evt_info.evt_id and evt_stat.evt_stat='8001' and evt_stat.evt_date=%s and evt_info.evt_name=%s ''' cursor_moia.execute(sql_evt_stat,[evt_date,evt_name]) conn_moia.commit() res_evt_stat = cursor_moia.fetchall() for each in res_evt_stat: evt_res = each[0] if evt_res == 0: print("发送失败","事件名称:",evt_name,"事件日期:",evt_date) sys.stdout.flush() evtResList[evt_name]='F' else : print("发送成功", "事件名称:", evt_name, "事件日期:", evt_date) sys.stdout.flush() evtResList[evt_name] = 'S' try: cursor_moia.close() conn_moia.close() except Exception as e: print('数据库关闭失败:', e) exit(3) evtNo = [] evtSucc = [] evtFail = [] for key, value in evtResList.items(): if value == 'N': evtNo.append(key) if value == 'S': evtSucc.append(key) if value == 'F': evtFail.append(key) print("信号暂未发送个数:", len(evtNo), "信号发送成功个数:", len(evtSucc), "信号发送失败个数:", len(evtFail)) sys.stdout.flush() if len(evtNo)==0: break else: stime=5 print(datetime.datetime.now(),"本次循环结束 休眠%s秒" % stime) sys.stdout.flush() time.sleep(stime)
if len(evtFail)!=0: print("全部信号发送完成, 其中发送成功个数:%s, 发送失败个数:%s, 请检查!" % (len(evtSucc), len(evtFail))) print("发送失败事件清单如下:") for item in evtFail: print(item) exit(9) else: print("全部信号发送完成, 发送成功个数:%s !" % len(evtSucc))
|