#============================================================= #執行次數紀錄 #------------------------------------------------------------- monitor.serialnum(serialnumfile, codenum, errnum) #============================================================= #花費時間 #------------------------------------------------------------- timeE = monitor.timing() timeSP = timeE - timeS #============================================================= #文件寫入點2 寫入log檔 #------------------------------------------------------------- monitor.toFile(logfilename, daytime, timeS, timeE, filename, state, sSQL, aSQL) #============================================================= # log to SQL #------------------------------------------------------------- missSQL = sSQL - aSQL #漏掉資料量 try: #建立 SQL 語法 insert & createtable sql, sqlcreate = monitor.logSQL(logtable, daytime, timeSP, filename, state, sSQL, aSQL, missSQL, logdb) #log to SQL # 1.create table monitor.pymysqlcon(logip, loguser, logpw, logdb, sqlcreate) # 2.insert log monitor.pymysqlcon(logip, loguser, logpw, logdb, sql)
db.commit() db.close() driver.get('https://www.518.com.tw/') driver.find_element_by_css_selector('li.remove-all > a').click() #...... #------------------------------------------------------------- #success serialnum serialnum = monitor.serialnum(serialnumfile,codenum,errnum) #sql驗證(請修改sSQL & sql兩個變數) #------------------------------------------------------------- try: #請select出此次執行已進入SQL行數 sql = "select count(*) as cou from `518`.`518_test` where `time` between DATE_ADD(NOW(), INTERVAL -1 DAY) and NOW();" db, cursor ,accounts = monitor.pymysqlcon("127.0.0.1", 'root', 'root', "518" ,sql) aSQL = accounts[0]['cou'] except: sSQL = 0 aSQL = 99 #------------------------------------------------------------- print('應進入行數:',sSQL) print('已進入 SQL 行數:', aSQL) timeE = monitor.timing() timeSP = timeE -timeS monitor.toFile(logfilename,daytime, timeS, timeE,ip ,filename ,state ,sSQL ,aSQL ,serialnum) missSQL = sSQL - aSQL #請先建立好 SQL table #log to SQL 請輸入 ip account password databases query sql = "INSERT INTO `518`.`logtest` VALUES ('{}', {:.2f}, '{}', '{}', '{}', {}, {}, {}, {});".format(daytime,timeSP,ip,filename,state,sSQL,aSQL,missSQL,serialnum) monitor.pymysqlcon("127.0.0.1", 'root', 'root', "518" ,sql) driver.close()