47 lines
1.6 KiB
Python
47 lines
1.6 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(mp, title, content, author, timestamp, link,weixin_id):
|
||
|
try:
|
||
|
with psycopg2.connect(G2) as connection:
|
||
|
with connection.cursor() as cursor1:
|
||
|
cursor1.execute("select * from dashboard_weixin where weixinid = '%s'" % (weixin_id))
|
||
|
r = cursor1.fetchall()
|
||
|
for i in r:
|
||
|
with connection.cursor() as cursor:
|
||
|
id = uuid.uuid4()
|
||
|
cursor.execute(
|
||
|
"insert into dashboard_weixin_data(id,weixin_id, mp, title, content, author, timestamp, link,created,updated) values (%s,%s,%s,%s,%s,%s,%s,%s,now(),now() )"
|
||
|
, (str(id), i[0], mp, title, content, author, timestamp, link))
|
||
|
connection.commit()
|
||
|
except:
|
||
|
pass
|
||
|
if __name__ == '__main__':
|
||
|
sql = 'select * from weixin_article'
|
||
|
cursor.execute(sql)
|
||
|
results = cursor.fetchall()
|
||
|
for r in results:
|
||
|
print(r)
|
||
|
mp = r[1]
|
||
|
title = r[2]
|
||
|
content = r[3]
|
||
|
author = r[4]
|
||
|
timestamp = r[5]
|
||
|
link = r[6]
|
||
|
weixin_id = str(link).split('biz=')[1].split('&mid')[0]
|
||
|
insert(mp, title, content, author, timestamp, link,weixin_id)
|
||
|
|
||
|
|