113 lines
5.6 KiB
Python
113 lines
5.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import csv
|
|
import uuid
|
|
import os
|
|
import psycopg2
|
|
|
|
from pip._vendor import chardet
|
|
|
|
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
|
G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#'
|
|
|
|
|
|
def insert_weixin(name,code,identificationcode,function,articleurl,biz):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select id from dashboard_organization where name = '%s'" % (name))
|
|
connection.commit()
|
|
row = cursor.fetchall()
|
|
for r in row:
|
|
o_id = r[0]
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
"insert into dashboard_weixin(id,code, created, updated,organization_id,image,alias,status,weixinid,attention, remark,identificationcode,function,articleurl) values (%s,%s,now(),now(),%s,'weixin.png','',1,%s,'','',%s,%s,%s)"
|
|
, (str(id), code, o_id, biz,identificationcode,function,articleurl))
|
|
print(o_id)
|
|
connection.commit()
|
|
|
|
def insert_weibo(name,code,identificationcode,function,articleurl,biz):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select * from dashboard_organization where name = '%s'" % (name))
|
|
connection.commit()
|
|
row = cursor.fetchall()
|
|
for r in row:
|
|
o_id = r[0]
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
"insert into dashboard_weibo(id,code, created, updated,organization_id,image,alias,status,weiboid,attention, remark,identificationcode,function,articleurl) values (%s,%s,now(),now(),%s,'weibo.png','',1,%s,'','',%s,%s,%s)"
|
|
, (str(id), code, o_id, biz,identificationcode,function,articleurl))
|
|
print(o_id)
|
|
connection.commit()
|
|
def insert_toutiao(name,code,identificationcode,function,articleurl,biz):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select id from dashboard_organization where name = '%s'" % (name))
|
|
connection.commit()
|
|
row = cursor.fetchall()
|
|
for r in row:
|
|
o_id = r[0]
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
"insert into dashboard_toutiao(id,code, created, updated,organization_id,image,alias,status,toutiaoid,attention, remark,identificationcode,function,articleurl) values (%s,%s,now(),now(),%s,'toutiao.png','',1,%s,'','',%s,%s,%s)"
|
|
, (str(id), code, o_id, biz,identificationcode,function,articleurl))
|
|
print(o_id)
|
|
connection.commit()
|
|
def insert_qita(name,code,identificationcode,type,function,articleurl,biz):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select id from dashboard_organization where name = '%s'" % (name))
|
|
connection.commit()
|
|
row = cursor.fetchall()
|
|
for r in row:
|
|
o_id = r[0]
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
"insert into dashboard_qita(id,code, created, updated,organization_id,image,alias,status,qitaid,attention, remark,identificationcode,type,function,articleurl) values (%s,%s,now(),now(),%s,'qita.png','',1,%s,'','',%s,%s,%s,%s)"
|
|
, (str(id), code, o_id, biz,identificationcode,type,function,articleurl))
|
|
print(o_id)
|
|
connection.commit()
|
|
def insert_douyin(name,code,identificationcode,function,articleurl,biz):
|
|
with psycopg2.connect(G2) as connection:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select id from dashboard_organization where name = '%s'" % (name))
|
|
connection.commit()
|
|
row = cursor.fetchall()
|
|
for r in row:
|
|
o_id = r[0]
|
|
id = uuid.uuid4()
|
|
cursor.execute(
|
|
"insert into dashboard_douyin(id,code, created, updated,organization_id,image,alias,status,douyinid,attention, remark,identificationcode,function,articleurl) values (%s,%s,now(),now(),%s,'douyin.png','',1,%s,'','',%s,%s,%s)"
|
|
, (str(id), code, o_id, biz,identificationcode,function,articleurl))
|
|
print(o_id)
|
|
connection.commit()
|
|
if __name__ == '__main__':
|
|
|
|
with open('D:/2020/舆论监测平台/XMTJC/数据/总.csv',encoding='utf-8') as csvfile:
|
|
reader = csv.reader(csvfile)
|
|
for r in reader:
|
|
if r[1] != '新媒体类型':
|
|
name = r[1]
|
|
code = r[4]
|
|
identificationcode = r[3]
|
|
type = r[7]
|
|
function = r[8]
|
|
articleurl = r[12]
|
|
biz = r[13]
|
|
if r[7] == '微信订阅号' or r[7] == '微信服务号':
|
|
insert_weixin(name,code,identificationcode,function,articleurl,biz)
|
|
elif r[7] == '新浪微博':
|
|
insert_weibo(name,code,identificationcode,function,articleurl,biz)
|
|
elif r[7] == '今日头条':
|
|
insert_toutiao(name,code,identificationcode,function,articleurl,biz)
|
|
elif r[7] == '抖音短视频':
|
|
insert_douyin(name,code,identificationcode,function,articleurl,biz)
|
|
else:
|
|
insert_qita(name,code,identificationcode,type,function,articleurl,biz)
|
|
|