当前位置:网站首页>(small information for children to children-03) batch template production of basic information collection folder for children (including PDF, word and certificate folder)
(small information for children to children-03) batch template production of basic information collection folder for children (including PDF, word and certificate folder)
2022-06-13 11:34:00 【reasonsummer】
One 、 Background needs
2022 year 6 May shanghai Yousheng primary school registration , Because the epidemic is all on the Internet , How to let parents use mobile phones 、 The computer Independent modification “ Cursive table ” Information , how Quickly collect all kinds of documents from parents , It has become the focus of the big class teachers .
Two 、 Operation idea :
from All in one Downloaded 28 Children PDF Cursive table ,PDF file name = name ( Id card ).py
To make it easier to find , Add... Before each child's name Student number ( Two digit number ),PDF file name = Student name ( Id card ).py
Through the collection of various information , I think the first folder sent to parents should include four items “.
1、 For viewing PDF Cursive table ( Fixed format )
2、 You can edit, add and modify information DOCX file ( Edit format )
3、 Document collection :” Registered residence in Shanghai “ Folder ( contains 6 Subfolders ), Registered residence in other provinces ( It contains 8 Subfolders )
4、word A written record of the modification process + Three parents Electronic signature ( Screenshot or PDF)( The teacher tidies up )
01 Shanghai household cadastral Proof required :
02 Registered residence in other provinces Proof required :
03 Modification process and signature The default six folders :
After thinking, we need the above files and folders .
3、 ... and 、 Code demonstration
( One ) Operation preparation :
This code is made of various code collages , I know a thing or two about the principle , No flexibility . Therefore, the dead end method must be prepared in full accordance with the operating instructions , To ensure successful operation .
1. route :
(1) stay D New under disk test stay test Under the new info.
(2) Put the baby X Share PDF File put in d:\test\info
(3) stay D:\test\info Under the new “ Text document ”=py file
Please make py Document bar ( The code is as follows )
from logging import root
import time
print('-----------202206 Large shift registration draft folder generates code in batch -----------')
print('--------------------------------------------------------')
print('\n Operation instructions \n')
print('1. Select the folder :\n open VS page - top left corner “ file ”-“ Open folder ”-D-test-info( Click the mouse info, Open the lower right corner “ Select the folder ”)\n')
print('2. newly build D disc Next test Next info Three level directory \n')
print('3. Put this code py Put it in D disc Next test Next info Inside (py and PDF Same level directory )\n')
print('--------------------------------------------------------')
time.sleep(1)
answer=int(input(' Have you set it up according to the operating instructions ?\n Have been set =1, No settings =2\n'))
if answer==1:
print('----------- Get ready . hold PDF Put the rough list in a folder :D Discoid test\info-----------')
time.sleep(3)
print('----------- The first 1 Step . Script implementation : take PDF File transfer Word-----------')
print('----------- Purpose . Parents use Word Modify the information ( For example, the scarlet letter is bold )-----------')
time.sleep(3)
import os
from pdf2docx import Converter
import time
import PyPDF2
def pdf_word():
global file_path
file_path = r'D:\test\info'
# Create a corresponding new folder , For later storage word file
new_file = os.makedirs(file_path+ '\\1')# Generated 1 Folder , But don't import the data into it
# new_file = os.makedirs(file_path + '\\docx')# Generated docx Folder
# new_file_path = r'D:\test\nn\docx' # Generated docx The files are all in docx Under the folder
new_file_path = r'D:\test\info'# Generate docx Document and pdf The files are in the same directory
# It needs to be in the same folder
# Get all... Under the target folder pdf
for root, dirs, files in os.walk(file_path):
#
# root: route
# dirs: Catalog
# files: file
#
for f in files:
suff_name = os.path.splitext(f)[1] # Judge whether the file name suffix is pdf
if suff_name != '.pdf':
pass
else:
file_name = os.path.splitext(f)[0] # Get the file name
target_pdf_name = file_path + '\\' + f # The goal is pdf File path
word_name = new_file_path + '\\' + file_name + '.docx' # The conversion word file
print(word_name)
try:
PyPDF2.PdfFileReader(open(target_pdf_name, "rb")) # test pdf Whether the file can be opened normally
cv = Converter(target_pdf_name)
cv.convert(word_name)
cv.close()
except PyPDF2.utils.PdfReadError:
print(target_pdf_name, "Invalid PDF file")
except OSError:
print("Not PDF file")
else:
pass
if __name__ == '__main__':
start = time.time()
pdf_word()
end = time.time()
print('task is over: %.2f' % (end-start))
# hold docx Move files to PDF At the same level , Delete docx Folder
# Delete 1 Folder , If there is no new folder 1,pdf turn docx It doesn't work . So you must create a new one ( In order not to copy an empty one 1 file , Delete the empty folder here
os.rmdir(r'D:\test\info\1')
print('----------- The first 1 Step .end-----------')
print('----------- The first 2 Step . Children's cursive table pdf and docx Import a folder with the same name -----------')
print('----------- Purpose . Batch generate personal folders ----------------')
import os
import shutil
# Get all the files and directories in the current directory
# file_path2='D:/test/'
listDir = os.listdir(r'D:\test\info') # D/test/info
# Traverse
folders1=[]
for dir in listDir:
# Judge if it is a folder or yourself, then ignore
if os.path.isdir(dir) or '01 Merge .py'== dir:
continue
# Separate file name and extension , Get the file name without suffix
dirName = os.path.splitext(dir)[0]
# Determine whether a directory with the same name exists ,
# If it does not exist, this directory will be created , Move a file with the same name to a directory ,
# If it exists, it will be moved to this directory directly
if not os.path.exists(dirName):
os.mkdir(dirName)
# os.makedirs(dirName)
shutil.move(dir, dirName)
folders1.append(dirName)
folders2=[]
[folders2.append(x) for x in folders1 if x not in folders2]
print(folders2)
print('----------- The first 2 Step .end-----------')
print('----------- The first 3 Step . Every toddler folder contains “ Supporting materials - Certificate photo " Folder -----------')
print('----------- Purpose . It is convenient for parents to request according to the file name , Put all kinds of proof materials into it ----------------')
import os
import itertools
import time
file_dir=r'D:/test/info'
for root,dirs,files in os.walk(file_dir,topdown=False): # extract root All first level paths 、 Secondary path ( No files ) dir=03 04 Folder ,file file name
# print(root) # D:/test/info\03 D:/test/info\04 D:/test/info Two three-level paths 、1 First level path
# print(dirs) #[][]['03', '04'] Two folders together
# print(files)#[][]['01 Merge .py', '02 pack .py', '123.py'] Non folder py
for name in dirs: #name come from ['03', '04'] Traversal cycle ,
root_path=os.path.join(root,name) # Combined file path + Folder name root+03\root+04
# print(b)
folders1=['01 Registered residence in Shanghai ']
genders1 = ['01 Account book ( The first 1 Page address Home page Children's page )','02 property ownership certificate ( First to last pages or lease contract )',
'03 Certificate of separation of people and households ( Residence admission offers )','04 Parental ID card ','05 Child's birth certificate ','06 Other proofs ']# second level
for folder1,gender1 in itertools.product(folders1, genders1):#folder= First level directory address gender= Added subfolders
os.makedirs(os.path.join(root_path,folder1,gender1))
# os.mkdir(os.path.join(b,folder1,gender1))
folders2=['02 Registered residence in other provinces ']
genders2 = ['01 Account book ( The first 1 Page address Home page Children's page )','02 property ownership certificate ( The first page to the last page or the filing of the lease contract )',
'03 Both parents' ID cards ','04 Residence permits or certificates of both parents and children ','05 Integral proof ','06 Child's birth certificate ',
'07 Parents' social security payment or flexible employment certificate ','08 Other proofs ']# second level
for folder2,gender2 in itertools.product(folders2, genders2):#folder= First level directory address gender= Added subfolders
os.makedirs(os.path.join(root_path,folder2,gender2))
folders3=['03 Modification process and signature ']
genders3 = ['01 The first 1 Time modification ','02 The first 2 Time modification ','03 The first 3 Time modification ','04( Draft table revision ) Signature ','05( Positive table preview ) Signature ','06( Positive statement receipt ) Signature ']# second level
for folder3,gender3 in itertools.product(folders3, genders3):#folder= First level directory address gender= Added subfolders
os.makedirs(os.path.join(root_path,folder3,gender3))
print('----------- The first 3 Step .end-----------')
print('----------- The first 4 Step . Each toddler folder is packaged rar-----------')
print('----------- Purpose . It is convenient to send parents' wechat separately ----------------')
def compress(input_file, output_file, root_path,
rar_path='C:/"Program Files (x86)"/WinRAR/WinRAR.exe'):
#rar_path='C:/"Program Files (x86)"/360/360zip/360zip.exe'):
"""
call CMD Command to compress files / Folder
Parameters
----------
input_file : Files that need to be compressed / Folder name . Which level of directory to start from , At which level will the compression begin ;
output_file : The output path of the compressed file and its compressed file name ;
It can be .rar, .zip;
root_path: input_file In the directory ;
rar_path : WinRAR Installation path of software ,
The default is 'C:/"Program Files"/WinRAR/WinRAR.exe'.
NOTE: Be sure to add a double quotation mark when there are spaces in the path and file name !!
"""
cmd_command = r'%s a %s %s' % (rar_path, output_file, input_file)
os.chdir(root_path) # Switch working directory
os.system(cmd_command)
if os.system(cmd_command)==0:
print('Successful backup to', output_file)
else:
print('Backup FAILED', input_file)
root_path = "D:/test/info"
lists = os.listdir(root_path)
for fp in lists:
if '01 Merge .py'== fp :
continue
input_file = '"' + fp + '"' # The path and file to be compressed , Add an extra quotation mark
output_file = '"' + fp + '.rar"' # The output path and file name of the compressed file , Add an extra quotation mark
compress(input_file, output_file, root_path)
print('----------- The first 4 Step .end-----------')
if answer==2:
print(' I'll set it up / Wait a minute ')
pass
2.VS Folder settings
This article has a fixed open path , Please be sure to set , Otherwise, it is an error
Basic setup is complete .
( Two ) Code content parsing constitutes :
1、 Brief needs :
take 3 individual PDf File conversion to 3 individual Word,3 set Word+PDF Merge into your own folder with the same name (3 individual ).3 Insert... In all folders “ Registered residence in Shanghai ”“ Registered residence in other provinces ”“ Modification process and signature ” Three identical folders . Finally pack RAR file
2、 The construction idea and steps of the code are as follows :
3、 Running effect picture display .
In each folder , Insert the same 3 A folder , The following code is mainly used :
At this point, each child folder has 5 File
(4) Video demonstration of code running and file generation process
python Yousheng small information registration folder packaging video
3、 ... and 、 Actual application feedback
5、 ... and 、 Summarize and reflect :
In the early (5 month 31 Japan ): Segment testing
from 5 month 31 The production started on the th “ The small information registration folder of Yousheng is packed .py”, Various problems have emerged , At first, four groups of code were run to complete the file packaging step by step .
effect : Increase of efficiency 、 Accuracy rate
This five group data package , Provide parents with easy to modify DOCX, You can also add various certificates according to the name of the certificate folder ,( Package and send back ) after , Uniform file name format ( Student name + Content ) It is convenient for teachers to quickly classify , Provision of electronic information , The manual input of teachers is greatly reduced 、 The workload of manual sorting ,
later stage (6 month 11 Japan ): Series test
stay 11 Days after commissioning , In the end in 6 month 11 All the blocking points were opened on the th , take “pdf turn docx""PDF+Docx Contract to folder with the same name ”“ Three fixed folders are added to each file ( And sub files )‘”“ pack rar”, Together .
effect : Understand the extraction and combination of paths .
Crack batch join “ Three fixed folders and sub files ” The problem of , It took a long time .root and file Extraction of , And combinations , Delete extra folders , Don't pack py Documents, etc. .python Any small details in the will directly affect the results of the program .
6、 ... and 、 Sentiment :
For the practical task of kindergarten office , I studied the code of this package file , Although it is highly efficient after completion , But for this one-time project ( You Sheng small certificate collection batch folder packaging ), It takes dozens of times to study , This process often makes me feel whether it is worth ?
Maybe only you can master more programming methods , Able to cope with the ever-changing teaching 、 When there is a batch demand for office , You will really feel that the learning time paid in the early stage is worth it 、 It's valuable .
边栏推荐
- [tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
- 关于 SAP Spartacus CmsService.getComponentData 可能的优化思路
- ARM64 上的性能怪兽:API 网关 Apache APISIX 在 AWS Graviton3 上的安装和性能测试
- Multithreading starts from the lockless queue of UE4 (thread safe)
- 日志1111
- Nim游戏阶梯 Nim游戏和SG函数应用(集合游戏)
- socket编程(上)
- MFC custom button to realize color control
- [tcapulusdb knowledge base] Introduction to tmonitor system upgrade
- ue5 小知识点 random point in Bounding Boxf From Stream
猜你喜欢
【TcaplusDB知识库】TcaplusDB机型管理介绍
17 pictures: read and understand the first domestic guide for mainframe security capacity building
元宇宙土地:是什么让数字房地产变得有价值
View the default MySQL password in the pagoda
Discord机器人开发
Socket programming (medium)
The leader said he would go online tomorrow, but he didn't know the development process at all
查询当前电脑cpu核心数
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (II)
【ROS】MoveIt-rviz-七自由度机械臂仿真
随机推荐
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (II)
ARM64 上的性能怪兽:API 网关 Apache APISIX 在 AWS Graviton3 上的安装和性能测试
《自然-通讯》| 用机器学习和时间序列数据为气候变化下的武装冲突风险建模
MFC custom button to realize color control
[tcapulusdb knowledge base] tcapulusdb doc acceptance - Introduction to creating game area
Easyclick run code snippet out null
容斥原理(能被整除的数)
2021CCPC网络赛榜单
Multithreading starts from the lockless queue of UE4 (thread safe)
统计特殊子序列数目(0,1,2)DP
1051. 高度检查器
St table learning
【TcaplusDB知识库】TcaplusDB新增机型介绍
Type de condition pour ts Advanced
break algorithm---multi-interface
Four methods of finding combinatorial numbers
Ubuntu installs MySQL compressed package for future reference
数位DP例题
Ue5 random point in bounding boxf from stream
Apache APISIX v2.14.1 探索性版本发布,进军更多领域