77 lines
3.4 KiB
Python
77 lines
3.4 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!@#'
|
|
|
|
if __name__ == '__main__':
|
|
# with open('F:/用户激活情况表.csv','w', newline='',encoding='utf-8') as csvfile:
|
|
# writer = csv.writer(csvfile)
|
|
# writer.writerow(
|
|
# ["姓名", "单位", "职位", "是否激活", "市", "县"])
|
|
# with psycopg2.connect(G2) as connection:
|
|
# with connection.cursor() as cursor:
|
|
# cursor.execute(
|
|
# "select * from auth_user")
|
|
# for c in cursor:
|
|
# with connection.cursor() as cursor1:
|
|
# cursor1.execute(
|
|
# "select * from dashboard_userprofile where user_id = '%s'" %(c[0]))
|
|
# for c1 in cursor1:
|
|
# with connection.cursor() as cursor2:
|
|
# cursor2.execute(
|
|
# "select * from dashboard_organization where id = '%s'" % (c1[10]))
|
|
# for c2 in cursor2:
|
|
#
|
|
# x = None
|
|
# if c1[7] == 1:
|
|
# x = '已激活'
|
|
# else:
|
|
# x = '未激活'
|
|
# writer.writerow(
|
|
# [c1[1], c2[1], c1[5], x, c2[4], c2[5]])
|
|
|
|
# ------------------------------替换市和县---------------------------------------
|
|
with open('F:/用户激活情况表1.csv','w', newline='',encoding='utf-8') as csvfile:
|
|
writer = csv.writer(csvfile)
|
|
writer.writerow(
|
|
["姓名", "单位", "职位", "是否激活", "市", "县"])
|
|
with open('F:/用户激活情况表.csv',encoding='utf-8') as csvfile:
|
|
reader = csv.reader(csvfile)
|
|
for r in reader:
|
|
if r[0] != '姓名':
|
|
name = r[0]
|
|
o = r[1]
|
|
post = r[2]
|
|
status = r[3]
|
|
shi = r[4]
|
|
xian = r[5]
|
|
s = None
|
|
s1 = None
|
|
with psycopg2.connect(G2) as connection:
|
|
if shi:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute(
|
|
"select * from dashboard_area_code_2020 where code = '%s'" %(shi))
|
|
for c in cursor:
|
|
s = c[2]
|
|
else:
|
|
s = shi
|
|
if xian:
|
|
with connection.cursor() as cursor1:
|
|
cursor1.execute(
|
|
"select * from dashboard_area_code_2020 where code = '%s'" %(xian))
|
|
for c1 in cursor1:
|
|
s1 = c1[2]
|
|
else:
|
|
s1 = xian
|
|
print(s1)
|
|
writer.writerow(
|
|
[name, o, post, status, s, s1])
|
|
|