28 KiB
28 KiB
In [ ]:
import os,sys,shutil
import openpyxl
import math
import json
fi_xls = 'data/北京低碳监测.xlsx'
old = []
dict1 = {}
dict2 = {}
dict3 = {}
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
depart = []
for n in range(2,sheet.max_row+1):
m_name = sheet.cell(n,6).value
m_depart = sheet.cell(n,3).value
if sheet.cell(n,4).value is not None:
dict1[int(sheet.cell(n,4).value)] = [m_name,m_depart]
fi_xls = 'data/低碳院人员邮件信息.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
m_dm = sheet.cell(n,3).value
m_depart = sheet.cell(n,2).value
m_name = sheet.cell(n,4).value
m_email = sheet.cell(n,3).value+sheet.cell(n,6).value
if sheet.cell(n,3).value is not None:
dict2[sheet.cell(n,3).value] = [m_name,m_depart,m_email]
#print(dict2)
for item in dict1.keys():
old.append(item)
old.sort()
for n in old:
m_name = dict1[n][0]
m_depart = dict1[n][1]
for item in dict2.values():
if m_name in item and m_depart in item:
dict3[int(n)] = [m_name,m_depart,item[2]]
break
dict3[232] = ['王锐','新能源技术研究中心','20063984@ceic.com']
dict3[213] = ['王锐','新能源技术研究中心','17240222@ceic.com']
fi_xls = 'data/汇总表.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
m_dm = int(sheet.cell(n,1).value)
m_pn = sheet.cell(n,6).value
m_xb = sheet.cell(n,3).value
m_birth = sheet.cell(n,4).value
if sheet.cell(n,1).value is not None:
dict3[m_dm].append(m_xb)
dict3[m_dm].append(m_birth)
dict3[m_dm].append(m_pn)
#print(dict2)
with open('data/低碳院人员信息.json','w') as fl2:
json.dump(dict3,fl2,ensure_ascii=False) In [ ]:
import openpyxl
import json
dict1 = {}
fl_name = 'data/低碳院人员信息.json'
with open(fl_name,'r') as fl:
m_xx = json.load(fl)
#print(m_xx)
fi_xls = 'data/适应A组.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,3).value is not None:
m_dm = str(sheet.cell(n,1).value)
m_name = sheet.cell(n,2).value
m_email = m_xx[m_dm][2]
m_pn = m_xx[m_dm][3]
dict1[m_dm.rjust(5,"0")] = [m_name,m_email,m_pn]
m_dm = []
for item in dict1.keys():
m_dm.append(item.rjust(5,"0"))
m_dm.sort()
wb = openpyxl.Workbook()
sheet = wb.active
i = 2
sheet[f'A1'] = '编号'
sheet[f'B1'] = '姓名'
sheet[f'C1'] = '邮箱'
sheet[f'D1'] = '电话'
for item in m_dm:
sheet[f'A{i}'] = item
sheet[f'B{i}'] = dict1[item][0]
sheet[f'C{i}'] = dict1[item][1]
sheet[f'D{i}'] = dict1[item][2]
i+=1
wb.save('data/A.xlsx') In [ ]:
import openpyxl
import json
dict1 = {}
fl_name = 'data/低碳院人员信息.json'
with open(fl_name,'r') as fl:
m_xx = json.load(fl)
#print(m_xx)
list1 = []
fi_xls = 'data/适应A组.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,3).value is not None:
m_dm = str(sheet.cell(n,1).value)
m_name = sheet.cell(n,2).value
m_email = m_xx[m_dm][2]
m_pn = m_xx[m_dm][3]
dict1[m_dm.rjust(5,"0")] = [m_name,m_email,m_pn]
m_dm = []
for item in dict1.keys():
m_dm.append(item)
m_dm.sort()
for s in m_dm:
if dict1[s][1]:
list1.append(dict1[s][1])
#print(';'.join(list1))
m_len = len(list1)
if m_len > 200:
mail_list1 = []
mail_list2 = []
mail_list3 = []
for i in range(0,100):
mail_list1.append(list1[i])
for i in range(100,200):
mail_list2.append(list1[i])
for i in range(200,m_len):
mail_list3.append(list1[i])
#print(len(mail_list1),len(mail_list2))
print(';'.join(mail_list1))
print('\n')
print(';'.join(mail_list2))
print('\n')
print(';'.join(mail_list3))
else:
mail_list1 = []
for i in range(0,m_len):
mail_list1.append(list1[i])
print(';'.join(mail_list1))In [ ]:
import openpyxl
import json
dict1 = {}
fl_name = 'data/低碳院人员信息.json'
with open(fl_name,'r') as fl:
dict1 = json.load(fl)
#print(m_xx)
list1 = ['适应A组','适应B组','适应C组','提高组']
for item in list1:
fi_xls = f'data/{item}.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,3).value is not None:
m_dm = str(sheet.cell(n,1).value)
dict1[m_dm].append(item)
wb = openpyxl.Workbook()
sheet = wb.active
sheet['A1'] = '编号'
sheet['B1'] = '姓名'
sheet['C1'] = '性别'
sheet['D1'] = '出生日期'
sheet['E1'] = '部门'
sheet['F1'] = '邮件'
sheet['G1'] = '联系电话'
sheet['H1'] = '组别'
i = 2
for k, v in dict1.items():
sheet[f'A{i}'] = k
sheet[f'B{i}'] = v[0]
sheet[f'C{i}'] = v[3]
sheet[f'D{i}'] = v[4]
sheet[f'E{i}'] = v[1]
sheet[f'F{i}'] = v[2]
sheet[f'G{i}'] = v[5]
sheet[f'H{i}'] = v[6]
i+= 1
wb.save('data/低碳院人员运动分组表.xlsx') In [ ]:
import openpyxl
import math
import json
dict1 = {}
#print(m_xx)
fi_xls = 'data/成绩得分4.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,1).value is not None:
m_dm = sheet.cell(n,1).value
list1 = []
for i in range(2,28):
list1.append(sheet.cell(n,i).value)
dict1[m_dm] = list1
fi_xls = 'data/成绩得分5.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,1).value is not None:
m_dm = sheet.cell(n,1).value
list1 = []
for i in range(2,28):
list1.append(sheet.cell(n,i).value)
dict1[m_dm] = list1
#print(dict1)
wb = openpyxl.Workbook()
sheet = wb.active
i = 1
for k, v in dict1.items():
m_bh = str(k).rjust(5,"0")
list2=['B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA']
sheet[f'A{i}'] = k
for ii in range(0,26):
sheet[f'{list2[ii]}{i}'] = v[ii]
ii+= 1
i+= 1
wb.save('data/合并.xlsx')
In [ ]:
import openpyxl
import math
import json
dict1 = {}
fl_name = 'data/低碳院人员信息.json'
with open(fl_name,'r') as fl:
m_xx = json.load(fl)
wb = openpyxl.Workbook()
sheet = wb.active
sheet['A1'] = '编号'
sheet['B1'] = '姓名'
sheet['C1'] = '性别'
sheet['D1'] = '出生日期'
sheet['E1'] = '部门'
sheet['F1'] = '邮件'
sheet['G1'] = '联系电话'
i = 2
for k, v in m_xx.items():
m_bh = str(k).rjust(5,"0")
sheet[f'A{i}'] = k
sheet[f'B{i}'] = v[0]
sheet[f'C{i}'] = v[3]
sheet[f'D{i}'] = v[4]
sheet[f'E{i}'] = v[1]
sheet[f'F{i}'] = v[2]
sheet[f'G{i}'] = v[5]
i+= 1
wb.save('data/低碳院人员信息表.xlsx') In [ ]:
import json
dict1 = {}
fl_name = 'data/低碳院报告.json'
with open(fl_name,'r') as fl:
m_xx = json.load(fl)
print(len(m_xx.keys()))In [ ]:
import openpyxl
import math
import json
import pymysql
fi_xls = 'data/低碳院多点账号20230217.xlsx'
chongming = ['王锐','王楠','郭强','王涛','张静']
dict1 = {}
dict2 = {}
dict3 = {}
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "SELECT a.name ,a.phone,b.avatar_id FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
if result[0] not in chongming:
dict2[result[0]] = [str(result[1]).strip(),result[2]]
#print(dict2)
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value is not None:
dict1[int(sheet.cell(n,1).value)] = [sheet.cell(n,2).value,sheet.cell(n,3).value,str(sheet.cell(n,4).value).strip()]
#print(dict1)
i = 1
for k, v in dict1.items():
if v[0] in dict2.keys() and v[2]!=dict2[v[0]][0]:
print(i,v[0],v[2],dict2[v[0]][1])
i+= 1In [ ]:
import json
import pymysql
import openpyxl
dict1 = {}
dict2 = {}
dict3 = {}
list1 = []
fi_xls = 'data/低碳院多点账号20230217.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value is not None:
list1.append(str(sheet.cell(n,4).value).strip())
#print(list1)
list2 = []
list3 = []
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "select * FROM Survey s WHERE s.surveyId IN ('psy6') AND s.updatedAt >'2022-11-01'"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
#dict2[result[0]] = [str(result[2]).strip(),result[1]]
dict2[result[0]] = str(result[2]).strip()
#print(dict2)
for k, v in dict2.items():
if v not in list1:
list2.append(v)
sql = "SELECT a.phone FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
list3.append(result[0])
#print(dict2)
for item in list2:
if item not in list3:
print(item)
In [ ]:
import json
import pymysql
import openpyxl
dict1 = {}
dict2 = {}
dict3 = {}
list1 = []
fi_xls = 'data/低碳院多点账号20230217.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value is not None:
list1.append(str(sheet.cell(n,4).value).strip())
#print(list1)
list2 = []
list3 = []
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "select * FROM Survey s WHERE s.surveyId IN ('psy4','tcmv2') AND s.updatedAt >'2022-11-01'"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
#dict2[result[0]] = [str(result[2]).strip(),result[1]]
dict2[result[0]] = str(result[2]).strip()
#print(dict2)
for k, v in dict2.items():
if v not in list1:
list2.append(v)
sql = "SELECT a.phone FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
list3.append(result[0])
#print(dict2)
for item in list2:
if item not in list3:
print(item)
In [6]:
import json
import pymysql
import openpyxl
dict1 = {}
dict2 = {}
dict3 = {}
list1 = []
fi_xls = 'data/低碳院人员信息表.xlsx'
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value is not None:
pn = str(sheet.cell(n,7).value).strip()
if pn not in list1:
list1.append(pn)
else:
print(pn)
In [ ]:
import json
import pymysql
import openpyxl
dict1 = {}
dict2 = {}
dict3 = {}
list1 = []
sql = "SELECT a.phone,a.name,c.unit FROM people as a,places_people as b,_ditan2 as c WHERE a.id =b.people_id AND c.id = b.avatar_id and b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
if result[0] not in list1:
list1.append(result[0])
else:
print(result[0])
print(list1)In [ ]:
import json
import pymysql
import openpyxl
dict1 = {}
dict2 = {}
dict3 = {}
list1 = []
sql = "SELECT a.phone,a.name,c.unit FROM people as a,places_people as b,_ditan2 as c WHERE a.id =b.people_id AND c.id = b.avatar_id and b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
if result[0] != None:
dict1[result[0]] = [result[1],result[2]]
#print(dict1)
sql = "select * FROM Survey s WHERE s.surveyId IN ('psy4','tcmv2') AND s.updatedAt >'2022-11-01'"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
#dict2[result[0]] = [str(result[2]).strip(),result[6]]
pn = str(result[2]).strip()
if pn in dict1.keys():
dict2.setdefault(pn,{})
dict2[pn].setdefault('item',[])
dict2[pn]['name'] = dict1[pn][0]
dict2[pn]['unit'] = dict1[pn][1]
dict2[pn]['item'].append(result[1])
#print(dict2)
for k, v in dict2.items():
list2 = []
ph = k
item = ','.join(v['item'])
name = v['name']
unit = v['unit']
list2 = [name,unit,ph,item]
list1.append(list2)
filename = 'data/北京低碳院问卷参与情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
In [ ]:
import openpyxl
import math
import json
import pymysql
fi_xls = 'data/低碳院人员信息表.xlsx'
chongming = ['王锐','王楠','郭强','王涛','张静']
dict1 = {}
dict2 = {}
dict3 = {}
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "SELECT a.name ,a.phone,b.avatar_id FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
if result[0] not in chongming:
dict2[result[0]] = [str(result[1]).strip(),result[2]]
#print(dict2)
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value is not None:
email = str(sheet.cell(n,6).value).strip()
name = str(sheet.cell(n,2).value).strip()
if name in dict2.keys():
bh = dict2[name][1]
dict1.setdefault(bh,{})
dict1[bh]['name'] = name
dict1[bh]['phone'] = dict2[name][0]
dict1[bh]['email'] = email
print(dict1)In [14]:
import openpyxl
import math
import json
import pymysql
fi_xls = 'data/低碳院人员信息表.xlsx'
chongming = ['王锐','王楠','郭强','王涛','张静']
dict1 = {}
dict2 = {}
dict3 = {}
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "SELECT a.name ,a.phone,b.avatar_id FROM people as a,places_people as b WHERE a.id =b.people_id AND b.place_id = 139"
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
bh = result[2]
dict2.setdefault(bh,{})
dict2[bh]['name'] = str(result[0]).strip()
if result[1] is not None:
dict2[bh]['phone'] = str(result[1]).strip()
#print(dict2)
wb = openpyxl.load_workbook(fi_xls)
sheet = wb.active
for n in range(2,sheet.max_row+1):
if sheet.cell(n,2).value not in chongming:
email = str(sheet.cell(n,6).value).strip()
name = str(sheet.cell(n,2).value).strip()
dict1[name] = email
for k, v in dict2.items():
if v['name'] in dict1.keys():
dict2[k]['email'] = dict1[v['name']]
#for k, v in dict2.items():
# if 'email' not in v.keys():
# print(k,v['name'])
for n in range(2,sheet.max_row+1):
email = str(sheet.cell(n,6).value).strip()
name = str(sheet.cell(n,2).value).strip()
pn = str(sheet.cell(n,7).value).strip()
dict3.setdefault(pn,{})
dict3[pn]['email'] = email
dict3[pn]['name'] = name
for k, v in dict2.items():
if 'phone' in v.keys() and v['phone'] in dict3.keys() and v['name'] == dict3[v['phone']]['name']:
dict2[k]['email'] = dict3[v['phone']]['email']
#for k, v in dict2.items():
# if 'email' not in v.keys():
# print(k,v['name'],v['phone'])
filename = 'data/低碳院邮件信息.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')47 张静 58 张静 109 王涛 209 王锐 228 王锐 273 王楠 378 郭强 408 王涛 433 王楠 465 郭强 494 王永涛 495 杨靖 496 李晓宝 497 王婧 498 徐滨 499 孙华宇 500 贾建慧 501 郝国政 502 崔双双 503 赵振慧 504 刘静远 505 陆斌 506 杜鹏 507 赵亮亮 508 张文秀 ok
In [ ]: