Demo entry 6353503

py

   

Submitted by anonymous on Mar 31, 2017 at 17:58
Language: Python. Code size: 1.6 kB.

        db = MySQLdb.connect("802.1x-db","username","password","dbname" )
        db2 = MySQLdb.connect("127.0.0.1","username","password","dbname")
        now = datetime.datetime.now()
        now = now + timedelta(days=-60)
        time_after = time.mktime(now.timetuple())
        time_after = int(time_after)
        old_log = Select_old_log(db,time_after)  // 获取60天前的日志id
        if old_log != False:
                for i in old_log:
                        sql = "DELETE FROM `1x_detail` WHERE `1x_detial`.`detail_id` = " + str(i[0])
                        cur.execute(sql)
                        k = k + 1
        cur = db2.cursor()
		//  删掉60天之前的日志
        result = get_max_detail_id(db2)   // 获取当前本地表中的日志id
        detail_id = result[0][0]
        a = Select_increment(db,detail_id) // 查询源表,获取需要增量同步的数据
        db.close()
        for i in a:
                value = '('+str(i[0])+',"'+str(i[1])+'","'+str(i[2])+'",'+str(i[3])+','+str(i[4])+','+str(i[5])+','+str(i[6])+','+str(i[7])+','+str(i[8])+',"'+str(i[9])+'","'+str(i[10])+'","'+str(i[11])+'","'+str(i[12])+'",'+str(i[13])+')'
                sql = "INSERT INTO .`1x_detail` (`detail_id`, `session_id`, `user_name`, `add_time`, `drop_time`, `bytes_in`, `bytes_out`, `bytes_in6`, `bytes_out6`, `user_ip`, `user_ip6`, `user_mac`, `total_bytes`, `time_long`) VALUES" + value
                if is_log_exist(db2,str(i[0])) == 0:
                        cur.execute(sql)
                        k = k + 1
        try:
                db2.commit()
        except:
                db2.roolback()
        db2.close()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).