53 KiB
53 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 [ ]:
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 [ ]:
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 [65]:
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 [68]:
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')
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 [74]:
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') 113 [['适应A组', '宗瑾', 0], ['适应A组', '范玉建', 0], ['适应A组', '小新卖蜡笔💚', 1], ['适应A组', '李轩', 1], ['适应A组', '赵文静', 1], ['适应A组', '啦啦啦', 2], ['适应A组', '沐风', 3], ['适应A组', '杨征', 4], ['适应A组', '毛毛李', 4], ['适应A组', 'Hansolo', 4], ['适应A组', '李旭影', 5], ['适应A组', '林泉', 5], ['适应A组', '海', 5], ['适应A组', '阮如玉', 7], ['适应A组', 'Qieyingli', 7], ['适应A组', '赵璐璐', 8], ['适应A组', '王绍亮', 9], ['适应A组', '冰王子', 10], ['适应A组', '贾小胖', 11], ['适应A组', 'yuandelin', 13], ['适应A组', '于双恩', 14], ['适应A组', '红太虎', 14], ['适应A组', '杨如意', 20], ['适应A组', 'Fan Yongsheng', 22], ['适应A组', '晓亚', 25], ['适应A组', 'Lan💐💐💐', 25], ['适应A组', '贺国锋', 28], ['适应A组', '闫瑞军', 29], ['适应A组', '呆呆(丹)🍀', 29], ['适应A组', '齐云龙', 35], ['适应A组', '高星', 42], ['适应A组', '高高兴兴', 43], ['适应A组', '孙任晖', 48], ['适应A组', '王海棠', 50], ['适应A组', '顺其自然', 73], ['适应A组', '老罗', 75], ['适应A组', 'Ssss', 77], ['适应A组', '阿白', 79], ['适应A组', 'Linge', 88], ['适应A组', '董春伟', 94], ['适应A组', 'LyuYJ', 95], ['适应A组', '阿杜', 71], ['适应B组', '宗瑾', 0], ['适应B组', '王涛', 0], ['适应B组', '张凡', 1], ['适应B组', '浩', 2], ['适应B组', '葱', 3], ['适应B组', '程萌', 3], ['适应B组', '无', 6], ['适应B组', 'Shuai', 22], ['适应B组', '。。。', 23], ['适应B组', '韩志华', 25], ['适应B组', '龙龙', 39], ['适应B组', 'YX~', 44], ['适应B组', 'liqiands', 45], ['适应B组', '比小熊', 57], ['适应B组', '欢欢', 63], ['适应B组', 'scofiedys', 64], ['适应B组', '武月', 103], ['适应C组', '宗瑾', 0], ['适应C组', '胜录', 0], ['适应C组', 'candy', 0], ['适应C组', '阳光雨露', 1], ['适应C组', '劉知邦', 1], ['适应C组', '方秋', 1], ['适应C组', '赵华博', 2], ['适应C组', '时㈥🇨🇳', 3], ['适应C组', '赛赛\ue305', 8], ['适应C组', '延鑫', 9], ['适应C组', '颜', 12], ['适应C组', '韦慧🎈', 12], ['适应C组', '许明', 23], ['适应C组', '康善娇', 25], ['适应C组', '王伟', 30], ['适应C组', '丁江涛', 31], ['适应C组', '城墙', 51], ['适应C组', '香龙', 53], ['适应C组', '🍜李为真', 54], ['适应C组', 'Ming', 57], ['适应C组', '王子鑫', 73], ['适应C组', 'Ophelia琪', 82], ['适应C组', '张寅灵', 82], ['适应C组', '张艳杰', 107], ['提高组', '宗瑾', 0], ['提高组', '小新卖蜡笔💚', 0], ['提高组', 'momo', 1], ['提高组', 'momo', 15], ['提高组', '郭建秋', 17], ['提高组', 'fumei🍭🍿', 62], ['提高组', '刘捷', 89], ['提高组', '赵明', 89]] ok
In [76]:
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 [ ]: