58 KiB
58 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 datetime
dict1 = {}
dict2 = {}
dict3 = {}
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = "SELECT b.avatar_id, a.name ,a.sex,a.birth 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[0]
name = str(result[1]).strip()
dict2.setdefault(bh,{})
dict2[bh]['name'] = name
dict2[bh]['sex'] = result[2]
#dict2[bh]['birth'] = result[3]
#print(result[3])
days = (datetime.date(2023, 3, 6)-result[3]).days
dict2[bh]['age'] = round(days/365)
filename = 'data/低碳院体测人员信息2023.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import time
import csv
filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k,v in dict1.items():
item[k] = v
#SQL语句为:
#SELECT a.item_id,a.performance,a.score,a.date AS DATE1,a.avatar_id,b.unit,b.name,a.date_joined FROM places_result AS a,_tianjin AS b WHERE a.place_id=134 AND a.avatar_id=b.id
re_ta = {}
dict1 = {}
list1 = []
#print("\n运动项目信息:")
filename = 'data/139.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
#line = re.sub('[\r\n\f ]{1,}', '', line)
list1.append(line)
#print(list1)
for result in list1:
user = str(result[4])
m_item = str(result[0])
re_ta.setdefault(user,{})
re_ta[user]['name'] = str(result[6])
re_ta[user]['unit'] = str(result[5])
item_name = item[m_item]['name']
re_ta[user].setdefault(item_name,{})
score = int(result[1])/item[m_item]['divisor']
re_ta[user][item_name]['成绩'] = f'{score} {item[m_item]["unit"]}'
re_ta[user][item_name]['得分'] =result[2]
filename = 'data/result_低碳院.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl)
print('ok')In [ ]:
import json
items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_低碳院.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/低碳院体测人员信息2023.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k,v in dict1.items():
print(k)
score = 0
i = 0
for k1,v1 in v.items():
if k1 in items:
score = score + int(v1['得分'])
i+=1
dict1[k]['age'] = dict2[k]['age']
dict1[k]['sex'] = dict2[k]['sex']
dict1[k]['score'] = round(score/i,2)
filename = 'data/result_低碳院.json'
with open(filename,'w') as fl:
json.dump(dict1, fl)
print('ok')In [ ]:
import os,sys,shutil
import json
import math
import openpyxl
filename = 'data/低碳院体测人员信息2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
fi_path = 'file/139/2023-03-08'
m_path = 'file/139/new'
old = []
fl=os.listdir(fi_path)
for fn in fl:
if os.path.isfile(fi_path + '/' + fn):
ofn = int(fn.split('.')[0])
old.append(ofn)
old.sort()
for n in old:
o_name = f'{fi_path}/{n}.pdf'
name = dict1[str(n)]['name']
n_name = f'{m_path}/{str(n).rjust(5,"0")}-{name}.pdf'
#print(o_name,n_name)
if not os.path.exists(n_name):
shutil.copyfile(o_name,n_name)
print(n_name)
In [ ]:
import json
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,59],[60,69]]
filename = 'data/result_低碳院.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 1
score = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
score = score+v['score']
i+=1
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i-1}人')
In [ ]:
import json
import openpyxl
items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_低碳院.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for item in items:
dict2.setdefault(item,{})
for k, v in dict1.items():
if item in v.keys():
dict2[item].setdefault('总体',[0,0])
if v['sex']==0:
sex = '男'
else:
sex = '女'
dict2[item].setdefault(sex,[0,0])
dict2[item]['总体'][0]= dict2[item]['总体'][0]+int(v[item]['得分'])
dict2[item]['总体'][1]= dict2[item]['总体'][1]+1
dict2[item][sex][0] = dict2[item][sex][0]+int(v[item]['得分'])
dict2[item][sex][1] = dict2[item][sex][1]+1
print(dict2)
title= []
zt= []
nan= []
nv = []
title.append('')
zt.append('总体')
nan.append('男性')
nv.append('女性')
for k, v in dict2.items():
title.append(k)
zt.append(round(v['总体'][0]/v['总体'][1],2))
if '男' in v.keys():
nan.append(round(v['男'][0]/v['男'][1],2))
else:
nan.append(' ')
if '女' in v.keys():
nv.append(round(v['女'][0]/v['女'][1],2))
else:
nv.append(' ')
list1 = []
list1.append(zt)
list1.append(nan)
list1.append(nv)
filename = 'data/低碳院不同性别成绩分析.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
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 ('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 [ ]:
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 [ ]:
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'])
dict2[465]['email'] = '17240051@@ceic.com'
filename = 'data/低碳院邮件信息.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
fl_name = 'data/低碳院邮件信息.json'
with open(fl_name,'r') as fl:
dict2 = json.load(fl)
dict2['465']['email'] = '20024422@ceic.com'
filename = 'data/低碳院邮件信息.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import pymysql
chongming = ['王锐','王楠','郭强','王涛','张静']
dict1 = {}
dict2 = {}
dict3 = {}
fl_name = 'data/低碳院邮件信息.json'
with open(fl_name,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
if v['name'] not in chongming and 'email' in v.keys():
dict3[v['name']] = {'phone':v['phone'],'email':v['email']}
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]
name = str(result[0]).strip()
dict2.setdefault(bh,{})
dict2[bh]['name'] = name
if name in dict3.keys():
dict2[bh]['email'] = dict3[name]['email']
if result[1] is not None:
dict2[bh]['phone'] = str(result[1]).strip()
dict2[465]['email'] = '17240051@@ceic.com'
filename = 'data/低碳院人员信息2023.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import glob
import os
filename = 'data/低碳院邮件信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
fls = glob.glob('file/139/2023-03-08/*.pdf')
for fi in fls:
bh = os.path.basename(fi).split('.')[0]
if bh in dict1.keys() and 'email' in dict1[bh].keys():
#print(bh,dict1[bh]['name'],dict1[bh]['email'])
#print(bh,dict1[bh]['name'])
dict2.setdefault(bh,{})
dict2[bh]['name'] = dict1[bh]['name']
dict2[bh]['email'] = dict1[bh]['email']
dict2[bh]['file'] = fi
#print(len(dict2))
filename = 'data/低碳院邮件列表.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import glob
import os
filename = 'data/低碳院邮件信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
print(dict1)In [ ]:
import json
import glob
import os
dict1 = {
'494': {'name': '王永涛', 'email': '20087867@ceic.com'},
'497': {'name': '王婧', 'email': '20084082@chnenergy.com.cn'},
'499': {'name': '孙华宇', 'email': '20086856@chnenergy.com.cn'},
'500': {'name': '贾建慧', 'email': '20084081@chnenergy.com.cn'},
'501': {'name': '郝国政', 'email': '20084079@chnenergy.com.cn'},
'502': {'name': '崔双双', 'email': '20084083@chnenergy.com.cn'},
'503': {'name': '赵振慧', 'email': '11234518@chnenergy.com.cn'},
'504': {'name': '刘静远', 'email': '20084080@chnenergy.com.cn'},
'505': {'name': '陆斌', 'email': '20087351@ceic.com'},
'506': {'name': '杜鹏', 'email': '12080316@chnenergy.com.cn'},
'507': {'name': '赵亮亮', 'email': '20086857@chnenergy.com.cn'},
'508': {'name': '张文秀', 'email': 'zhangwenxiu@nicenergy.com'}
}
dict2 = {}
fls = glob.glob('file/139/2022-12-31/*.pdf')
for fi in fls:
bh = os.path.basename(fi).split('.')[0]
if bh in dict1.keys() and 'email' in dict1[bh].keys():
#print(bh,dict1[bh]['name'],dict1[bh]['email'])
#print(bh,dict1[bh]['name'])
dict2.setdefault(bh,{})
dict2[bh]['name'] = dict1[bh]['name']
dict2[bh]['email'] = dict1[bh]['email']
dict2[bh]['file'] = fi
#print(len(dict2))
filename = 'data/低碳院邮件列表(新增).json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.header import Header
import smtplib
import requests
import time
import re
import json
filename = 'data/低碳院邮件列表(新增).json'
with open(filename,'r') as fl:
m_xx = json.load(fl)
for k, v in m_xx.items():
m_bh = str(k).rjust(5,"0")
fl_name = v['file']
fl = f"{m_bh}-{v['name']}.pdf"
m_rec = v['email']
from_addr = 'kmingedu@163.com' #发件邮箱
password = 'GKWUZXMVYKSSUSSL' #邮箱密码
smtp_server = 'smtp.163.com' #SMTP服务器,以新浪为例
server = smtplib.SMTP(smtp_server,25) #第二个参数为默认端口为25,有些邮件有特殊端口
msg = MIMEMultipart()
msg['Subject'] = Header("低碳清洁能源研究院体质监测报告(2023年3月)",'utf-8')
msg['From'] = Header('北京坤铭体质监测评估中心')
msg['To'] = Header(m_rec)
from_addr = 'kmingedu@163.com' #发件邮箱
password = 'GKWUZXMVYKSSUSSL' #邮箱密码
to_addr = m_rec #收件邮箱
att1 =MIMEApplication(open(fl_name, 'rb').read())
#att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att1.add_header('Content-Disposition','attachment',filename=fl)
msg.attach(att1)
try:
server.login(from_addr,password) #登录邮箱
server.sendmail(from_addr,to_addr,msg.as_string()) #将msg转化成string发出
server.quit
time.sleep(3)
print(f'{fl}邮件发送成功!')
except smtplib.SMTPException:
print ("Error: 无法发送邮件")
In [ ]:
import json
import glob
import os
filename = 'data/低碳院邮件信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
fls = glob.glob('file/139/2022-12-31/*.pdf')
for fi in fls:
bh = os.path.basename(fi).split('.')[0]
if bh in dict1.keys() and 'email' in dict1[bh].keys():
#print(bh,dict1[bh]['name'],dict1[bh]['email'])
#print(bh,dict1[bh]['name'])
dict2.setdefault(bh,{})
dict2[bh]['name'] = dict1[bh]['name']
dict2[bh]['email'] = dict1[bh]['email']
dict2[bh]['file'] = fi
#print(len(dict2))
filename = 'data/低碳院邮件列表202212.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import glob
import os
filename = 'data/低碳院邮件信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
fls = glob.glob('file/139/2022-12-31/*.pdf')
for fi in fls:
bh = os.path.basename(fi).split('.')[0]
if bh in dict1.keys() and 'email' not in dict1[bh].keys():
#print(bh,dict1[bh]['name'],dict1[bh]['email'])
print(bh,dict1[bh]['name'])
In [ ]:
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.header import Header
import smtplib
import requests
import time
import re
import json
filename = 'data/低碳院邮件列表(新增).json'
with open(filename,'r') as fl:
m_xx = json.load(fl)
for k, v in m_xx.items():
m_bh = str(k).rjust(5,"0")
fl_name = v['file']
fl = f"{m_bh}-{v['name']}.pdf"
m_rec = v['email']
from_addr = 'kmingedu@163.com' #发件邮箱
password = 'GKWUZXMVYKSSUSSL' #邮箱密码
smtp_server = 'smtp.163.com' #SMTP服务器,以新浪为例
server = smtplib.SMTP(smtp_server,25) #第二个参数为默认端口为25,有些邮件有特殊端口
msg = MIMEMultipart()
msg['Subject'] = Header("低碳清洁能源研究院体质监测报告(2022年12月)",'utf-8')
msg['From'] = Header('北京坤铭体质监测评估中心')
msg['To'] = Header(m_rec)
from_addr = 'kmingedu@163.com' #发件邮箱
password = 'GKWUZXMVYKSSUSSL' #邮箱密码
to_addr = m_rec #收件邮箱
att1 =MIMEApplication(open(fl_name, 'rb').read())
#att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att1.add_header('Content-Disposition','attachment',filename=fl)
msg.attach(att1)
try:
server.login(from_addr,password) #登录邮箱
server.sendmail(from_addr,to_addr,msg.as_string()) #将msg转化成string发出
server.quit
time.sleep(3)
print(f'{fl}邮件发送成功!')
except smtplib.SMTPException:
print ("Error: 无法发送邮件")
In [ ]:
import openpyxl
import json
fi_xls = 'data/低碳院小鹅通人员情况表.xlsx'
list1 = []
dict1 = {}
dict2 = {}
dict3 = {}
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 None:
break
else:
name = sheet.cell(n, 1).value.strip()
phone = str(sheet.cell(n, 5).value).strip()
#检查手机号码是否有重复
#if phone not in list1:
# list1.append(phone)
#else:
# print(name,phone)
dict1.setdefault(phone,{})
dict1[phone]['name'] = name
dict1[phone]['unit'] = sheet.cell(n, 6).value
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')
In [ ]:
import json
import os
import glob
import csv
fi_path = 'data/小鹅通/'
dict1 = {}
fl = glob.glob(f'{fi_path}*.csv')
list1 = []
for fn in fl:
#with open(fn,'r',newline='',encoding='gb18030') as csv_file:
with open(fn,'r',newline='') as csv_file:
fl1 = csv.reader(csv_file,delimiter=',')
header = next(fl1)
for line in fl1:
#line = re.sub('[\r\n\f ]{1,}', '', line)
list1.append(line)
for item in list1:
dict1.setdefault(item[0],{})
dict1[item[0]]['nick'] = item[1]
dict1[item[0]]['phone'] = item[11].strip()
dict1[item[0]]['progress'] = item[3]
filename = 'data/小鹅通人员信息.json'
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False) In [ ]:
import json
import os
filename = 'data/小鹅通人员信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict1.items():
phone = v['phone']
if phone in dict2.keys():
dict2[phone]['id'] = k
dict2[phone]['nick'] = v['nick']
dict2[phone]['progress'] = v['progress']
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')
In [ ]:
import openpyxl
import json
import os
import glob
import csv
import re
fi_path = 'data/小鹅通/打卡/'
fl = glob.glob(f'{fi_path}*.csv')
dict1 = {}
for fn in fl:
with open(fn,'r',newline='') as csv_file:
list1 = []
fl1 = csv.reader(csv_file,delimiter=',')
group = re.findall(r'百日筑基”健康打卡—(.+)的打卡信息》',fn)[0]
#print(group)
header = next(fl1)
#print(header)
header = next(fl1)
list2 = []
for line in fl1:
list2.append(line)
dict1[group] = list2
list1 = []
for item in header:
item = re.sub(r'\t','',item)
print(item)
list1.append(item)
print(list1)
dict1['header'] = list1
#print(dict1)
filename = 'data/小鹅通打卡信息.json'
with open(filename,'w') as fl:
json.dump(dict1, fl,ensure_ascii=False) In [ ]:
import json
import time
import csv
filename = 'data/小鹅通打卡信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
jiezhiri = '2022-11-21'
list_rq = dict1['header']
#print(list_rq)
num = list_rq.index(jiezhiri)
print(num)
list1 = list_rq[1:num+1]
list2 = []
#print(list1)
for k, v in dict1.items():
if k!='header':
for item in v:
nick = item[0]
record = item[1:num+1]
list2.append([k,nick,record.count('√')])
print(list2)
for item in list2:
nick = item[1]
unit = item[0]
for k, v in dict2.items():
if v['nick'] == nick and unit == v['unit']:
dict2[k]['daka'] = item[2]
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename, 'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok') In [ ]:
import json
import time
import csv
filename = 'data/低碳院小鹅通人员信息.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict2.items():
list2 = []
unit = v['unit']
name = v['name']
progress = v['progress']
if 'daka' in v.keys():
daka = v['daka']
else:
daka = 0
list2 = [unit,name,progress,daka]
list1.append(list2)
filename = 'data/低碳院百日强基情况表(截止到20221121).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list1:
sheet.append(row)
wb.save(filename)
In [ ]: