2021-01-07 10:51:58 +00:00
|
|
|
|
# 更新新媒体脚本,结果为有出入的新媒体列表。
|
|
|
|
|
'''
|
|
|
|
|
1,将excel转为csv,使用utf-8编码集。
|
|
|
|
|
2、获取csv内容
|
|
|
|
|
3、与数据库中的数据逐项对比
|
|
|
|
|
'''
|
|
|
|
|
import csv
|
|
|
|
|
import re
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
import psycopg2 as psycopg2
|
|
|
|
|
|
|
|
|
|
# code = None
|
|
|
|
|
# alias = None
|
|
|
|
|
# attention = None
|
|
|
|
|
# remark = None
|
|
|
|
|
# identificationcode = None
|
|
|
|
|
# function = None
|
|
|
|
|
# articleurl = None
|
|
|
|
|
# weixinid = None
|
|
|
|
|
# type = None
|
|
|
|
|
G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_csv_weixin(path):
|
|
|
|
|
with open(path, encoding='utf-8') as csvfile:
|
|
|
|
|
reader = csv.reader(csvfile)
|
|
|
|
|
for r in reader:
|
|
|
|
|
if r[1] == '删除':
|
|
|
|
|
print(r)
|
|
|
|
|
# with psycopg2.connect(G2) as connection:
|
|
|
|
|
# with connection.cursor() as cursor:
|
|
|
|
|
# cursor.execute(
|
|
|
|
|
# "delete from dashboard_qita where code = '%s'" %(re.sub('\s+', '', r[0]).strip()))
|
|
|
|
|
# connection.commit()
|
|
|
|
|
elif r[1] == '新增':
|
2021-02-06 06:50:55 +00:00
|
|
|
|
with open('D:/2021/舆论监测平台/数据/Task_All.csv',encoding='utf-8') as c:
|
2021-01-07 10:51:58 +00:00
|
|
|
|
t = csv.reader(c)
|
|
|
|
|
for i in t:
|
2021-01-11 13:08:52 +00:00
|
|
|
|
print(re.sub('\s+', '', r[0]).strip(),re.sub('\s+', '', str(i[4]+i[7])).strip())
|
|
|
|
|
if re.sub('\s+', '', r[0]).strip() == re.sub('\s+', '', str(i[4]+i[7])).strip():
|
2021-01-07 10:51:58 +00:00
|
|
|
|
|
|
|
|
|
with psycopg2.connect(G2) as connection:
|
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
|
try:
|
|
|
|
|
cursor.execute(
|
|
|
|
|
"select * from dashboard_organization where name = '%s'" % (
|
|
|
|
|
re.sub('\s+', '', i[1]).strip()))
|
|
|
|
|
connection.commit()
|
|
|
|
|
print(i[1] + '++++++++++++++++++++++++++++++++++++++++')
|
|
|
|
|
for c in cursor:
|
|
|
|
|
print(c[0] + "22222222222222222222222222222222222")
|
|
|
|
|
id = uuid.uuid4()
|
|
|
|
|
cursor.execute(
|
|
|
|
|
"insert into dashboard_qita(id,code, created, updated,organization_id,image,alias,status,qitaid,attention, remark,identificationcode,function,articleurl,type) values (%s,%s,now(),now(),%s,'qita.png','',3,%s,'','',%s,%s,%s,%s)",
|
|
|
|
|
(str(id), re.sub('\s+', '', i[4]).strip(), c[0], i[13], i[3], i[8], i[12],i[7]))
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
|
2021-01-11 13:08:52 +00:00
|
|
|
|
|
2021-01-07 10:51:58 +00:00
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-06 06:50:55 +00:00
|
|
|
|
set_csv_weixin('D:/2021/舆论监测平台/数据/数据库更新/新媒体对比结果_其他_账号名称更改.csv')
|