#!/usr/bin/env python
# _*_ conding:utf-8 _*_
import sys
import os
import time
import datetime
import MySQLdb
bb=datetime.datetime.now()
c_time=time.strftime("%Y%m%d",time.localtime(time.time()))
today=datetime.date.today()
oneday=datetime.timedelta(days=1)
yesterday=today-oneday
yes_last=datetime.datetime.strftime(yesterday,"%Y%m%d")
print yes_last
#print c_time
try:
conn1=MySQLdb.connect(host='192.168.1.17',user='dlan',passwd='root123',port=3306,db='chat')
conn2=MySQLdb.connect(host='192.168.1.17',user='dlan',passwd='root123',port=3306,db='test')
cur1 = conn1.cursor()
cur2 = conn2.cursor()
aa1='''select * from chat.honghong1_'''+yes_last
aa2 = "create table IF NOT EXISTS ip_limit_"+yes_last+" " +"(id int,name varchar(22),c_time datetime)"
cur1.execute(aa1)
bb=cur1.fetchall()
cur2.execute(aa2)
value=()
for i in xrange(len(bb)):
value=(bb[i])
db_insert="insert into"+' '+"ip_limit_"+yes_last +" "+ "values(%s,%s,%s)"
cur2.execute(db_insert,value)
print "OK"
conn2.commit()
print "--------"
conn1.commit()
cur1.close()
cur2.close()
conn1.close()
conn2.close()
except MySQLdb.Error,e:
print "Could not connect to MySQL server",e