newmediamonitoring/get_data_for_mysql_toutiao_...

45 lines
1.4 KiB
Python

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 insert(type, tid, cid, rid, username, content, time, reply_count, diggcount):
try:
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
"insert into dashboard_toutiao_comment(id,type, tid, cid, rid, username, content, time, reply_count, diggcount,created,updated) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now() )"
, (str(id),type, tid, cid, rid, username, content, time, reply_count, diggcount))
connection.commit()
except:
pass
if __name__ == '__main__':
sql = 'select * from toutiao_comment'
cursor.execute(sql)
results = cursor.fetchall()
for r in results:
print(r)
type = r[1]
tid = r[2]
cid = r[3]
rid = r[4]
username = r[5]
content = r[6]
time = r[7]
reply_count = r[8]
diggcount = r[9]
insert(type, tid, cid, rid, username, content, time, reply_count, diggcount)