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')