import time import uuid import psycopg2 import pymysql host = "210.72.82.249" user = "pom" password = "pomWechat2020" port = 3306 database = 'pomdb' mysql = pymysql.connect(host=host,user=user,password=password,port=port,database=database) cursor = mysql.cursor() G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#' def update(id, s): # try: with psycopg2.connect(G2) as connection: with connection.cursor() as cursor: cursor.execute( "update dashboard_weixin_data set timestamp = %s where id = %s" , (s,id)) connection.commit() # except: # pass if __name__ == '__main__': with psycopg2.connect(G2) as connection: with connection.cursor() as cursor: id = uuid.uuid4() cursor.execute( "select id,timestamp from dashboard_weixin_data") results = cursor.fetchall() for r in results: id = r[0] timestamp = r[1] s = time.strftime('%Y-%m-%d', time.localtime(int(timestamp))) print(id,s) update(id, s)