newmediamonitoring1/get_data_for_mysql_toutiao_...

53 lines
1.9 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(toutiao_id, tid, celltype, title, content, time, url, commentcount, readnum, likenum,shownum):
try:
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor1:
cursor1.execute("select * from dashboard_toutiao where toutiaoid = '%s'" % (toutiao_id))
r = cursor1.fetchall()
for i in r:
print(i[9])
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
"insert into dashboard_toutiao_data(id,toutiao_id, tid, celltype, title, content, time, url, commentcount, readnum, likenum,shownum,created,updated) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now() )"
, (str(id), i[0], tid, celltype, title, content, time, url, commentcount, readnum, likenum,
shownum))
connection.commit()
except:
pass
if __name__ == '__main__':
sql = 'select * from toutiao_article'
cursor.execute(sql)
results = cursor.fetchall()
for r in results:
print(r)
toutiao_id = r[1]
tid = r[3]
celltype = r[4]
title = r[5]
content = r[6]
time = r[7]
url = r[8]
commentcount = r[9]
readnum = r[10]
likenum = r[11]
shownum = r[12]
insert(toutiao_id, tid, celltype, title, content, time, url, commentcount, readnum, likenum, shownum)