20 KiB
20 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 [4]:
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+= 11 郝国政 18813095526 501 2 杜鹏 15910618307 506 3 魏垚 18765506895 232 4 赵亮亮 18610066890 507
In [8]:
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)
15210715398 13810886698
In [11]:
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)
15210715398 15006594388 15210715398 17326968610 17326968610
In [ ]: