2020-12-08 13:19:10 +00:00
|
|
|
|
# 更新新媒体脚本,结果为有出入的新媒体列表。
|
|
|
|
|
'''
|
|
|
|
|
1,将excel转为csv,使用utf-8编码集。
|
|
|
|
|
2、获取csv内容
|
|
|
|
|
3、与数据库中的数据逐项对比
|
|
|
|
|
'''
|
|
|
|
|
import csv
|
|
|
|
|
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 get_csv_weixin(path):
|
2020-12-10 06:27:23 +00:00
|
|
|
|
p_list = []
|
2020-12-08 13:19:10 +00:00
|
|
|
|
with open(path, encoding='utf-8') as csvfile:
|
|
|
|
|
reader = csv.reader(csvfile)
|
|
|
|
|
for r in reader:
|
|
|
|
|
if r[1] != '单位全称':
|
2020-12-25 00:55:34 +00:00
|
|
|
|
if '白银市' in r[10]:
|
2020-12-10 06:27:23 +00:00
|
|
|
|
p_list.append(r[14])
|
|
|
|
|
print(len(list(set(p_list))))
|
|
|
|
|
for l in list(set(p_list)):
|
|
|
|
|
print(l)
|
|
|
|
|
with psycopg2.connect(G2) as connection:
|
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
|
try:
|
|
|
|
|
cursor.execute(
|
|
|
|
|
"select * from dashboard_userprofile where name = '%s'" %(l))
|
|
|
|
|
connection.commit()
|
|
|
|
|
for c in cursor:
|
|
|
|
|
print(c[11])
|
|
|
|
|
id = uuid.uuid4()
|
|
|
|
|
cursor.execute(
|
2020-12-25 00:55:34 +00:00
|
|
|
|
"insert into dashboard_group_user(id,created, updated, group_id, user_id) values (%s,now(),now(),'4efd485e-2873-440d-b828-b58b39b9b0d2',%s)", (str(id), c[11]))
|
2020-12-10 06:27:23 +00:00
|
|
|
|
connection.commit()
|
|
|
|
|
except Exception as e:
|
2020-12-25 00:55:34 +00:00
|
|
|
|
print(e,'+++++++',l)
|
2020-12-08 13:19:10 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-12-25 00:55:34 +00:00
|
|
|
|
get_csv_weixin('F:/TASK_ALL.csv')
|