34 KiB
34 KiB
In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/天津石化员工检测花名册 (20221014).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
code = int(sheet.cell(n, 6).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 3).value
dict1['sex'] = sheet.cell(n, 4).value
dict1['unit'] = sheet.cell(n, 1).value
dict1['sub_unit'] = sheet.cell(n, 2).value
if sheet.cell(n,5).value is not None:
dict1['id_num'] = sheet.cell(n,5).value
person[code] = dict1
filename = 'data/天津石化人员名单.json'
with open(filename, 'w') as fl:
json.dump(person, 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/134_2210.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
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位/部门','车间/科室','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_天津.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
list2.append(str(k).rjust(8,'0'))
list2.append(v['name'])
list2.append(dict2[k]['sex'])
list2.append(dict2[k]['unit'])
list2.append(dict2[k]['sub_unit'])
for item in items:
if item in v.keys():
list2.append(v[item]['成绩'])
elif item =='name':
list2.append(v[item])
else:
list2.append('')
list1.append(list2)
filename = 'data/天津石化体测情况表(截至20221122).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [19]:
import json
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位/部门','车间/科室','身高','','体重','','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']
filename = 'data/result_天津.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
#print(k,dict2[str(k)]['name'])
list2 = []
list2.append(str(k).rjust(5,'0'))
list2.append(dict2[k]['name'])
list2.append(dict2[k]['sex'])
list2.append(dict2[k]['unit'])
list2.append(dict2[k]['sub_unit'])
for item in items:
if item in dict1[k].keys():
list2.append(dict1[k][item]['成绩'])
list2.append(dict1[k][item]['得分'])
elif item =='name':
list2.append(dict1[k][item])
else:
list2.append('')
list2.append('')
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)
print('ok') ok
In [ ]:
import json
import time
import csv
import os,sys,shutil
import glob
dict1 = {}
list1 = []
filename = 'data/134_2210.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)
for result in list1:
user = str(result[4])
dict1.setdefault(user,'2022-10-01')
m_date = result[7]
if m_date> dict1[user]:
dict1[user] = m_date
m_path = 'file/134'
fls = glob.glob(f'file/new/*.pdf')
for fn in fls:
#old = os.path.basename(fn).split('.')[0].rjust(8,'0')
old = os.path.basename(fn).split('.')[0]
mrq = str(dict1[old]).split(' ')[0].replace('-', '', 2)
if not os.path.exists(m_path + '/new/' + mrq):
os.mkdir(m_path + '/new/' + mrq)
n_name = f'{m_path}/new/{mrq}/{str(old).rjust(8,"0")}_{mrq}.pdf'
if not os.path.exists(n_name):
shutil.copyfile(fn,n_name)
print('ok!')In [ ]:
import json
import time
import csv
import os,sys,shutil
import glob
dict1 = {}
list1 = []
m_path = 'file/134'
mrq = '20221028'
if not os.path.exists(m_path + '/' + mrq):
os.mkdir(m_path + '/' + mrq)
fls = glob.glob(f'file/new/*.pdf')
for fn in fls:
#old = os.path.basename(fn).split('.')[0].rjust(8,'0')
old = os.path.basename(fn).split('.')[0]
n_name = f'{m_path}/{mrq}/{str(old).rjust(8,"0")}_{mrq}.pdf'
if not os.path.exists(n_name):
shutil.copyfile(fn,n_name)
print('ok!')In [ ]:
import os,sys,shutil
import json
import math
import glob
from pathlib import Path
fi_path = './file'
old = []
dict2 = {}
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
m_name = v['name']
m_depart = v['unit']
dict2[int(k)] = [m_name,m_depart]
fls = glob.glob(f'./file/*.pdf')
for fn in fls:
old.append(os.path.basename(fn).split('.')[0])
#print(fn)
for n in old:
o_name = f'{fi_path}/{n}.pdf'
if not os.path.exists(f'{fi_path}/new/{dict2[int(n)][1]}'):
os.mkdir(f'{fi_path}/new/{dict2[int(n)][1]}')
n_name = f'{fi_path}/new/{dict2[int(n)][1]}/{str(n).rjust(5,"0")}-{dict2[int(n)][0]}.pdf'
if not os.path.exists(n_name):
shutil.copyfile(o_name,n_name)
print(n_name)In [ ]:
import os,sys,shutil
import json
import math
import glob
from pathlib import Path
fi_path = './file'
old = []
dict2 = {}
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
m_name = v['name']
m_depart = v['unit']
dict2[int(k)] = [m_name,m_depart]
fls = glob.glob(f'./file/*.pdf')
for fn in fls:
old.append(os.path.basename(fn).split('.')[0])
for n in old:
o_name = f'{fi_path}/{n}.pdf'
new_path = Path('file/new',dict1[n]['unit'],dict1[n]['sub_unit'])
new_path.mkdir(parents = True, exist_ok = True)
n_name = Path(new_path,f'{str(n).rjust(7,"0")}-{dict2[int(n)][0]}.pdf')
if not os.path.exists(n_name):
shutil.copyfile(o_name,n_name)
print(n_name)
print('ok')In [18]:
import json
import openpyxl
import os
import glob
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
m_path ='./file'
fls = glob.glob(f'file/*.pdf')
list1 = []
for fn in fls:
list2 = []
code = os.path.basename(fn).split('.')[0]
list2 = [code.rjust(7,"0"),dict1[code]['name'],dict1[code]['unit'],dict1[code]['sub_unit']]
list1.append(list2)
title = ['编号','姓名','单位/部门','车间/科室',]
filename = 'data/天津石化体测情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import fitz
from pdf2image import convert_from_path, convert_from_bytes
import os,sys
import tempfile
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
import img2pdf
import glob
import shutil
def covert2pic(old_fn):
if os.path.exists('.pdf'): # 临时文件,需为空
shutil.rmtree('.pdf')
os.mkdir('.pdf')
with tempfile.TemporaryDirectory() as path:
images_from_path = convert_from_path(old_fn, dpi=100,fmt='jpg', output_folder='.pdf')
def pic2pdf(new_fn):
fl1=glob.glob('.pdf/*.jpg')
fl1.sort()
a4inpt = (img2pdf.mm_to_pt(210),img2pdf.mm_to_pt(297))
layout_fun = img2pdf.get_layout_fun(a4inpt)
with open(new_fn,"wb") as f:
f.write(img2pdf.convert(fl1,layout_fun=layout_fun))
print(f'{new_fn}转换成功!')
def pdfz(sor, obj, zoom):
covert2pic(zoom)
pic2pdf(obj)
fi_path = 'file/134/20221122/'
fl = glob.glob(f'{fi_path}*.pdf')
for fn in fl:
new_fn = fi_path+'new/'+os.path.basename(fn)
covert2pic(fn)
pic2pdf(new_fn)
shutil.rmtree('.pdf')
print('ok!')
In [ ]:
import json
import openpyxl
title = ['编号','姓名','性别','单位/部门','车间/科室']
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/result_天津.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
if k not in dict2.keys():
list2 = [k,dict1[k]['name'],dict1[k]['sex'],dict1[k]['unit'],dict1[k]['sub_unit'],]
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)
print('ok!')In [ ]:
import os,sys,shutil
import glob
import time
fi_path = 'file/'
fls = glob.glob(f'{fi_path}*.pdf')
m_date = time.strptime('2022-10-28','%Y-%m-%d')
for fn in fls:
c_time = time.gmtime(os.path.getctime(fn))
if c_time > m_date:
n_name = f'{fi_path}new/{os.path.basename(fn)}'
if not os.path.exists(n_name):
shutil.copyfile(fn,n_name)
print(n_name)
In [ ]:
import json
import openpyxl
title = ['编号','姓名','性别','单位/部门','车间/科室']
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/result_天津.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
print(len(dict2),len(dict1),)In [22]:
import json
import openpyxl
title = ['编号','姓名','性别','单位/部门','车间/科室']
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/134_xinli.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[4])
list3 = []
for k, v in dict1.items():
list2 = []
if k not in list1:
list2 = [k,dict1[k]['name'],dict1[k]['sex'],dict1[k]['unit'],dict1[k]['sub_unit'],]
list3.append(list2)
filename = 'data/天津石化未参加心理测试人数统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list3:
sheet.append(row)
wb.save(filename)
print('ok!')ok!
In [20]:
import json
import openpyxl
title = ['编号','姓名','性别','单位/部门','车间/科室']
filename = 'data/天津石化人员名单.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
filename = 'data/134_xinli.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
print(line[4])1731990 1730445 1733543 3402384 1732997 1737697 1730575 1730370 1739948 3442741 1730359 3362198 3417263 1730439 1733749 3440898 1730989 1730356 1735371 1732814 1730913 1736882 1733497 3362212 1731589 1739001 1731819 1732459 3125774 1730902 3362662 1731856 1737990 3125699 3317857 1730219 1732471 3317863 1734383 3499245 1739589 1733813 3499240 1734246 3125710 3499237 3499243 3499253 1739362 3428692 1739050 1737160 1732665 3287806 1731058 1733868 1733867 1731561 3374924 3167516 3287818 3422008 1734221 1733715 3428694 1734188 1536861 3125698 1730538 3428695 3499244 1732461 1739419 3499257 1735528 3252962 1534670 3125708 1736685 3317910 3287811 3499250 3499252 1733962 1732064 1532672 1735489 1732061 1736599 1736711 1738767 1739302 1733200 1733921 1739427 1730169 1739308 1535224 3145487 3452129 3391160 1532563 1730119 1732176 3362572 3394990 1739239 1730527 3145535 3362148 3417105 1735004 1730099 1738145 3417344 3391150 1735011 1739366 1733562 1736119 3468164 1735730 3286619 1738273 3440494 1736766 1738693 3440490 1738688 1736104 1730461 3499700 1739760 1121028 1731513 1732257 1731552 1122144 1738750 1737455 3499719 1736319 1736146 1736909 3499696 1731467 1732266 1732170 1731539 3362183 3499712 1731534 1731510 1731532 1731442 1739826 1731524 3318695 1731469 1736750 3499705 1731444 3468014 3499693 1731476 3499702 3440472 1731514 3499691 1730766 1731487 1733004 1732263 1732815 1088006 1731509 1734184 1731511 1731443 3499708 1730580 1731540 1731449 3286600 3468152 3468033 1731535 1731520 3145577 1731545 1732809 3440496 1733354 1731461 1733157 3442666 3499720 1731472 1732805 1737993 1731500 1739223 3499710 3499718 1731496 1732808 1730648 1731459 3499689 1731529 1731956 1731457 1731471 1738961 1731502 1739835 1732803 1736917 1731386 1731935 1738682 3468160 1732253 3168143 3318687 1737044 1731489 1730524 1739289 1730599 1731477 3468147 3468012 1736728 1731497 1731773 1731468 3287821 1732921 1731463 1736129 1121117 1730586 1730522 1736757 1730550 3499711 3468183 1731486 1738690 1730470 1730593 1731464 1738669 1736743 3499715 1738641 1732807 1736794 1736798 1731465 1738668 1732269 1730468 3145776 1730649 1730612 1739417 1732802 1736729 3468010 1736755 1730639 1731479 1738245 1731538 3499695 1731491 1739006 1730962 3440495 1730616 1731537 1730430 1730163 1732804 1731518 1733541 1731221 1731478 1731840 1737054 1738505 1730052 3391167 3440899 1088010 1730578 3468015 1731482 1732252 1738654 1730230 1730267 1732164 1731875 1730519 1733549 1739010 1739125 1738942 1737065 1732810 3468042 1730244 1730256 1736505 3145483 1731951 1739918 1733503 1738877 1738999 1731536 1739924 1732784 1738890 1738673 1736841 1732682 1738542 1739011 1733733 1740092 1734764 1739014 1739812 1735318 1730650 1738495 1740086 1730656 1738891 3499698 1730657 1739242 1730584 1730651 1730581 1731525 3499703 1730592 1739005 1738876 1730630 1730108 3145594 1730589 1730611 1733725 1736884 3468184 3362172 3362657 1737052 1738861 1735247 3362161 1738700 1733559 1730239 1739007 3442721 1738885 1857524 1731662 1733782 1736720 1738998 1730658 1731475 1738888 1738889 1730266 3145554 1732778 1730467 3499706 3499694 1737420 1731904 1740109 1739647 1739761 1738835 3468162 1738865 1738902 1738915 1735380 1738867 1730306 1739810 3145529 1736754 1121100 1731531 1738911 1731473 1731553 1738538 1730628 1738991 1732206 1733427 3499249 1730582 1737562 1737618 1738958 1737345 1736762 1738968 1739198 1738884 1739763 1739161 1738643 1735007 3145482 3068728 3499688 1738684 1738646 1736320 1738680 1730771 3499704 1733518 1738631 1738914 1735375 3362186 1738857 3499251 1730005 1739121 1730585 3452130 3362163 3417166 3467827 1730383 1738519 1737605 3417279 1732991 3468100 1732698 3442764 1730167 1732265 1738869 1737176 1121078 3145495 1737454 1738834 3442659 1738938 1738937 3145484 3442703 1738969 1731523 1738527 3467917 1733724 1732002 1731076 1739002 1731235 1732144 3318680 1738517 1730394 1738903 1731111 1739128 1732850 1733502 1733498 1738677 1739235 3417267 1732864 1732169 1733703 1738882 1732889 1735641 1733380 1739944 1731422 1732254 3449693 1736753 1733740 1730406 1737424 1730621 1737364 1736723 3468166 1731289 1738841 1733756 1730405 1731501 1739855 1730254 1739806 3286601 1733257 1733699 3145498 1735003 1733721 31215 1732156 1733256 3467834 1731665 3145605 1739061 1733146 1055173 1731680 1736134 1736160 3442807 1732873 1730788 1732871 3442791 3442753 3145569 1733493 1732166 1739015 1088005 1739220 3145488 3145556 3442762 1732904 1088001 1733531 1305017 1730653 3468804 3499669 1732267 1735436 1736588 1103009 1529378 52781 3145452 1730080 3505717 1736872 1733742 1736764 1735650 1736721 1736585 3499690 3499607 1735299 53058 1730386 1738943 3467868 1739915 3452127 1736565 1736551
In [ ]: