-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_auto-1-1.py
149 lines (77 loc) · 3.31 KB
/
doc_auto-1-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from docx import Document
from docx.shared import Inches
from docxtpl import DocxTemplate
import os
import sys
folder = sys.argv[1]
current_working_directory=os.getcwd()
lis =['Job Title', 'Job Grade', 'Business Unit', 'Department', 'Job Type',
'Location', 'Objective/Purpose of Job', 'REPORTING RELATIONSHIPS', 'Reports to',
'Supervises', 'JOB DUTIES / RESPONSIBILITIES / ACCOUNTABILITIES', 'Internally Relates with',
'Externally Relates with', 'Budgetary Responsibility']
full_path_of_folder=os.path.join(current_working_directory, folder)
list_of_files_in_dir=os.listdir(full_path_of_folder)
try:
os.mkdir("{}/new_JDS".format(current_working_directory))
except FileExistsError:
pass
try:
os.mkdir("{}/bad_files".format(current_working_directory))
except FileExistsError:
pass
for file in list_of_files_in_dir:
document=Document("{}/{}".format(full_path_of_folder, file))
Job_title=document.tables[0].rows[0].cells[3].text
reports_to=document.tables[0].rows[5].cells[3].text
budgetary_responsibility=document.tables[0].rows[8].cells[3].text
duties_and_responsiblities=document.tables[0].rows[10].cells[0].text.strip().split('\n')
list_duties_and_responsiblities=[]
for items in duties_and_responsiblities:
if items.strip():
list_duties_and_responsiblities.append(items)
job_purpose=document.tables[0].rows[3].cells[3].text
job_grade=document.tables[0].rows[0].cells[8].text
department=document.tables[0].rows[1].cells[8].text
business_unit=document.tables[0].rows[1].cells[3].text
job_type=document.tables[0].rows[2].cells[3].text
location=document.tables[0].rows[2].cells[8].text
supervises=document.tables[0].rows[5].cells[8].text
internally_relates_with=document.tables[0].rows[7].cells[3].text
externally_relates_with=document.tables[0].rows[7].cells[8].text
education_and_requirements=document.tables[0].rows[12].cells[0].text.strip().split('\n')
list_education_and_requirements=[]
for items in education_and_requirements:
if items.strip():
list_education_and_requirements.append(items)
context={
'Job_title':
Job_title,
'reports_to':
reports_to,
'list_duties_and_responsiblities':
list_duties_and_responsiblities,
'list_education_and_requirements':
list_education_and_requirements,
'job_purpose':job_purpose,
'budgetary_responsibility':budgetary_responsibility,
'externally_relates_with': externally_relates_with,
'internally_relates_with': internally_relates_with,
'supervises': supervises,
'job_type' : job_type,
'location' : location,
'business_unit' : business_unit,
'department': department,
'job_grade' : job_grade
}
new_doc=DocxTemplate("template.docx")
new_doc.render(context)
for keys in context:
for item in lis:
if context[keys]==item:
new_doc.save('bad_files/new_{}'.format(file))
break
if 'new_{}'.format(file) not in os.listdir(os.path.join(current_working_directory, 'bad_files')):
new_doc.save('new_JDS/new_{}'.format(file))
print('All done, you will find your properly created files in the new_JDS folder, located in your current directory')
print('='*20)
print('You would find the bad ones in bad_files folder, located in your current working directory')