-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDFtest.py
More file actions
256 lines (209 loc) · 9.92 KB
/
Copy pathPDFtest.py
File metadata and controls
256 lines (209 loc) · 9.92 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import PyPDF2
import re
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.writer.excel import ExcelWriter
from openpyxl.cell import Cell
EquipmentList=[]
EquipmentListCon ={'Manufacturer':'SPEAG', 'Device':'Device','Type':'Type','SN':'Serial number','DateOfCal':'Date of last calibration','Vaild period':'Valid period'}
EquipmentList.append(list(EquipmentListCon))
EquipmentListConDAE =[]
EquipmentListConPROBE =[]
EquipmentListConPHANTOM =[]
PageConList=[]
PageCon ={'TEST data':'TEST data', 'File name':'File name','DUT':'DUT','Type':'Type', 'Serial':'Serial',\
'Medium used f':'Medium used f','Medium conductivy':'Medium conductivy','Medium permittiy':'Medium permittiy',\
'Frequency':'Frequency','Duty Cycle':'Duty Cycle','Probe type':'Probe type','Probe SN':'Probe SN','Probe Calibrate DATE':'Probe Calibrate DATE',\
'Sensor-Surface':'Sensor-Surface','DAE SN':'DAE SN','DAE Calibrate DATE':'DAE Calibrate DATE',\
'Phantom':'Phantom','Phantom Type':'Phantom Type','Phantom Serial':'Phantom Serial',\
'Area Scan dx':'Area Scan dx','Area Scan dy':'Area Scan dy','Zoom Scan dx':'Zoom Scan dx','Zoom Scan dy':'Zoom Scan dy','Zoom Scan dz':'Zoom Scan dz',\
'1-g SAR':'1-g SAR','10-g SAR':'10-g SAR','Power drift':'Power drift'}
PageConList.append(list(PageCon.values()))
pdfFileObj = open(r'C:\Users\Sun Shanbin\Desktop\PDF\test.pdf.', 'rb')
pdfReader =PyPDF2.PdfFileReader(pdfFileObj)
#print(pdfReader.numPages)
# print(pageCont + '\n')
def TiQuInfo(Page):
pageObj = pdfReader.getPage(Page)
pageCont = pageObj.extractText()
# if Page == 4:
# print(pageCont)
#TO DO Search Date
matchObj = re.search(r'Date:.*? ([0-9].*[0-9])\S', pageCont, re.M|re.I)
if matchObj:
# print('TEST data:', matchObj.group(1))
PageCon['TEST data'] = matchObj.group(1)
else:
# print('Date no match')
PageCon['TEST data'] = 'Date no match'
#TO DO Search File name
matchObj = re.search(r' Lab\n(.*?)DUT: ', pageCont, re.M|re.S|re.I)
if matchObj:
print('File name:', matchObj.group(1))
PageCon['File name'] = matchObj.group(1)
else:
print('File name no match')
PageCon['File name'] ='File name no match'
#TO DO Search DUT
matchObj = re.search(r'DUT: (.*?); Type: (.*?); Serial: (.*?)\s', pageCont, re.M|re.I)
if matchObj:
PageCon['DUT'] = matchObj.group(1)
PageCon['Type'] = matchObj.group(2)
PageCon['Serial'] = matchObj.group(3)
else:
PageCon['DUT'] = 'DUT name no match'
PageCon['Type'] = 'DUT name no match'
PageCon['Serial'] = 'DUT name no match'
#TO DO Search Medium fre:
matchObj = re.search(r'f = (.*?) MHz;', pageCont, re.M|re.I)
if matchObj:
print('Medium used f =', matchObj.group(1)+' MHz')
PageCon['Medium used f'] = matchObj.group(1)
else:
print('Medium fre no match')
PageCon['Medium used f'] = 'Medium fre no match'
#TO DO Search Medium parameters:
matchObj = re.search(r'= (\d.\d*?) S/m;.*?= (.*?);', pageCont, re.M|re.I)
if matchObj:
print('Medium conductivy f =', matchObj.group(1)+' S/m')
print('Medium permittiy:', matchObj.group(2))
# print('Medium permittiy:', matchObj.group(3))
PageCon['Medium conductivy'] = matchObj.group(1)
PageCon['Medium permittiy'] = matchObj.group(2)
else:
print('Medium parameters no match')
PageCon['Medium conductivy'] = 'Medium parameters no match'
PageCon['Medium permittiy'] = 'Medium parameters no match'
#TO DO Search Frequency:
matchObj = re.search(r'Frequency: (.*?);Duty Cycle: ([0-9].*?)M', pageCont, re.M|re.S|re.I)
if matchObj:
print('Frequency:', matchObj.group(1))
print('Duty Cycle:', matchObj.group(2))
PageCon['Frequency'] = matchObj.group(1)
PageCon['Duty Cycle'] = matchObj.group(2)
else:
print('Frequency Duty Cycle no match')
PageCon['Frequency'] = 'Frequency & Duty Cycle no match'
PageCon['Duty Cycle'] = 'Frequency & Duty Cycle no match'
#TO DO Search Probe
matchObj = re.search(r'(EX3DV4|ES3DV3).*?SN([0-9]{4}).*?Calibrated: ([0-9].*?);',pageCont, re.M|re.S|re.I)
if matchObj:
print('Probe type:', matchObj.group(1))
print('Probe SN:', matchObj.group(2))
print('Probe Calibrate DATE:', matchObj.group(3))
PageCon['Probe type'] = matchObj.group(1)
PageCon['Probe SN'] = matchObj.group(2)
PageCon['Probe Calibrate DATE'] = matchObj.group(3)
if matchObj.group(2) not in EquipmentListConPROBE:
EquipmentListConPROBE.append(matchObj.group(2))
EquipmentListCon = {'Manufacturer': 'SPEAG', 'Device': 'Dosimetric E-Field Probe', 'Type': PageCon['Probe type'], 'SN': PageCon['Probe SN'],
'DateOfCal': PageCon['Probe Calibrate DATE'], 'Vaild period': 'One year'}
EquipmentList.append(list(EquipmentListCon.values()))
else:
print('Porbe no match')
PageCon['Probe type'] = 'Porbe no match'
PageCon['Probe SN'] = 'Porbe no match'
PageCon['Probe Calibrate DATE'] = 'Porbe no match'
#TO DO Search Sensor-Surface
matchObj = re.search(r'Sensor-Surface.*? (.*?mm)', pageCont, re.M|re.I)
if matchObj:
print('Sensor-Surface:', matchObj.group(1))
PageCon['Sensor-Surface'] = matchObj.group(1)
else:
print('Sensor-Surface: no match')
PageCon['Sensor-Surface'] = 'Sensor-Surface: no match'
#TO DO Search DAE
matchObj = re.search(r'DAE4.*?SN([0-9]+).*?Calibrated.*?([0-9].*?) ', pageCont, re.M|re.I)
if matchObj:
print('DAE SN:', matchObj.group(1))
print('DAE Calibrate DATE:', matchObj.group(2))
PageCon['DAE SN'] = matchObj.group(1)
PageCon['DAE Calibrate DATE'] = matchObj.group(2)
if matchObj.group(2) not in EquipmentListConDAE:
EquipmentListConDAE.append(matchObj.group(2))
EquipmentListCon = {'Manufacturer': 'SPEAG', 'Device': 'Data acquisition electronics', 'Type': 'DAE4', 'SN': PageCon['DAE SN'],
'DateOfCal': PageCon['DAE Calibrate DATE'], 'Vaild period': 'One year'}
EquipmentList.append(list(EquipmentListCon.values()))
else:
print('DAE no match')
PageCon['DAE SN'] = 'DAE no match'
PageCon['DAE Calibrate DATE'] = 'DAE no match'
#TO DO Search Phantom
matchObj = re.search(r'Phantom.*? (.*)?;.*?Type.*? (.*?);.*Serial.*? (.*?[0-9]{4})', pageCont, re.M|re.I)
if matchObj:
print('Phantom:', matchObj.group(1))
print('Phantom Type:', matchObj.group(2))
print('Phantom Serial:', matchObj.group(3))
PageCon['Phantom'] = matchObj.group(1)
PageCon['Phantom Type'] = matchObj.group(2)
PageCon['Phantom Serial'] = matchObj.group(3)
if matchObj.group(3) not in EquipmentListConPHANTOM:
EquipmentListConPHANTOM.append(matchObj.group(3))
EquipmentListCon = {'Manufacturer': 'SPEAG', 'Device': 'Twin Phantom ', 'Type': PageCon['Phantom Type'], 'SN': PageCon['Phantom Serial'],
'DateOfCal': 'NCR', 'Vaild period': 'NCR'}
EquipmentList.append(list(EquipmentListCon.values()))
else:
print('Phantom no match')
PageCon['Phantom'] = 'Phantom no match'
PageCon['Phantom Type'] = 'Phantom no match'
PageCon['Phantom Serial'] = 'Phantom no match'
#TO DO Search Area Scan dx
matchObj = re.search(r'Area Scan.*?dx=([0-9]+?mm).*?dy=([0-9]+?mm)', pageCont, re.M|re.I)
if matchObj:
print('Area Scan dx=:', matchObj.group(1))
print('Area Scan dy=:', matchObj.group(2))
PageCon['Area Scan dx'] = matchObj.group(1)
PageCon['Area Scan dy'] = matchObj.group(2)
else:
print('Area Scan dx no match')
PageCon['Area Scan dx'] = 'Area Scan dx no match'
PageCon['Area Scan dy'] = 'Area Scan dx no match'
#TO DO Search Zoom Scan dx
matchObj = re.search(r'Zoom Scan.*?dx=([0-9]{1,2}mm).*?dy=([0-9]{1,2}mm).*?dz=([0-9]{1,2}mm)', pageCont, re.M|re.I)
if matchObj:
print('Zoom Scan dx=:', matchObj.group(1))
print('Zoom Scan dy=:', matchObj.group(2))
print('Zoom Scan dz=:', matchObj.group(3))
PageCon['Zoom Scan dx'] = matchObj.group(1)
PageCon['Zoom Scan dy'] = matchObj.group(2)
PageCon['Zoom Scan dz'] = matchObj.group(3)
else:
print('Zoom Scan dx no match')
PageCon['Zoom Scan dx'] = 'Zoom Scan dx no match'
PageCon['Zoom Scan dy'] = 'Zoom Scan dx no match'
PageCon['Zoom Scan dz'] = 'Zoom Scan dx no match'
#TO DO Search SAR and drift
matchObj = re.search(r'[(]1 g[)] = (.*?) .*?[(]10 g[)] = (.*?) ' , pageCont, re.M|re.I)
if matchObj:
print('1-g SAR=:', matchObj.group(1))
print('10-g SAR=:', matchObj.group(2))
PageCon['1-g SAR'] = matchObj.group(1)
PageCon['10-g SAR'] = matchObj.group(2)
else:
print('SAR value no match')
PageCon['1-g SAR'] = 'SAR value no match'
PageCon['10-g SAR'] = 'SAR value no match'
#TO DO Search SAR and drift
matchObj = re.search(r'Power Drift = (.*?) ' , pageCont, re.M|re.I)
if matchObj:
print('Power drift =:', matchObj.group(1))
PageCon['Power drift'] = matchObj.group(1)
else:
print('Power drift no match')
PageCon['Power drift'] = 'Power drift no match'
PageConList.append(list(PageCon.values()))
# print('\n', PageConList)
# print('\n', EquipmentList)
def prtexcel():
wb = Workbook()
ws = wb['Sheet']
for b in range(0 ,len(PageConList)):
ws.append(PageConList[b])
ws1 = wb.create_sheet()
for b in range(0 ,len(EquipmentList)):
ws1.append(EquipmentList[b])
wb.save(r'C:\Users\Sun Shanbin\Desktop\PDF\TEST.xlsx')
# for Page in range(0,pdfReader.numPages):
for Page in range(0,pdfReader.numPages):
TiQuInfo(Page)
prtexcel()