From 2241ef6ffa749c3c00659df0285ed2d0469be0ee Mon Sep 17 00:00:00 2001 From: xieshen <1397910458@qq.com> Date: Thu, 10 Dec 2020 14:27:23 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=9B=B4=E6=8D=A2=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 新媒体更新脚本/添加矩阵成员.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/新媒体更新脚本/添加矩阵成员.py b/新媒体更新脚本/添加矩阵成员.py index 05a3a02..464eac6 100644 --- a/新媒体更新脚本/添加矩阵成员.py +++ b/新媒体更新脚本/添加矩阵成员.py @@ -22,13 +22,30 @@ G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=new def get_csv_weixin(path): - + p_list = [] with open(path, encoding='utf-8') as csvfile: reader = csv.reader(csvfile) for r in reader: if r[1] != '单位全称': - if '' in r[7]: - print(r) + if '兰州市' in r[10]: + 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( + "insert into dashboard_group_user(id,created, updated, group_id, user_id) values (%s,now(),now(),'dc85d7a7-5c9a-4aa1-b872-ebc16b1eb0e2',%s)", (str(id), c[11])) + connection.commit() + except Exception as e: + print(e) if __name__ == '__main__': get_csv_weixin('D:/2020/新媒体监测/TASK_ALL.csv')