/
validate.py
150 lines (137 loc) · 5.36 KB
/
validate.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
150
import os
from archives_tools import dacs
import openpyxl
import sys
import string
__location__ = (os.path.dirname(os.path.realpath(__file__)))
inputPath = os.path.join(__location__, "input")
daoFileList = []
def dateCheck(date, errorCount, lineCount, title):
if " " in date.strip():
try:
print ("Line " + str(lineCount) + ", DATE ERROR, invalid space: (" + str(date) + ") title: " + title)
except:
print ("Line " + str(lineCount) + ", DATE ERROR, invalid space: (" + str(date) + ")")
errorCount += 1
acceptList = ["/", "-", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
if date != "None":
for character in str(date).strip():
if not character in acceptList:
print (character)
try:
print ("Line " + str(lineCount) + ", DATE ERROR, invalid character: (" + str(date) + ") title: " + title)
except:
print ("Line " + str(lineCount) + ", DATE ERROR, invalid character: (" + str(date) + ")")
errorCount += 1
if "/" in date:
start, end = date.split("/")
if start > end:
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(date) + ") title: " + title)
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(date) + ")")
errorCount += 1
if "undated" in date.lower():
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(date) + ") title: " + title)
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(date) + ")")
errorCount += 1
return errorCount
for file in os.listdir(inputPath):
if file.endswith(".xlsx"):
filePath = os.path.join(inputPath, file)
wb = openpyxl.load_workbook(filename=filePath, read_only=True)
#validate sheets
for sheet in wb.worksheets:
checkSwitch = True
try:
if sheet["H1"].value.lower().strip() != "title":
checkSwitch = False
elif sheet["H2"].value.lower().strip() != "level":
checkSwitch = False
elif sheet["H3"].value.lower().strip() != "ref id":
checkSwitch = False
elif sheet["J6"].value.lower().strip() != "date 1 display":
checkSwitch = False
elif sheet["D6"].value.lower().strip() != "container uri":
checkSwitch = False
except:
print ("ERROR: incorrect sheet " + sheet.title + " in file " + file)
if checkSwitch == False:
print ("ERROR: incorrect sheet " + sheet.title + " in file " + file)
else:
#Read sheet info
print ("Reading sheet: " + sheet.title)
lineCount = 0
errorCount = 0
for row in sheet.rows:
lineCount += 1
if lineCount > 6:
try:
date = dacs.iso2DACS(str(row[10].value))
errorCount = dateCheck(str(row[10].value), errorCount, lineCount, row[8].value)
except:
errorCount += 1
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[10].value) + ") title: " + str(row[8].value))
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[10].value) + ")")
try:
date = dacs.iso2DACS(str(row[12].value))
errorCount = dateCheck(str(row[12].value), errorCount, lineCount, row[8].value)
except:
errorCount += 1
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[12].value) + ") title: " + str(row[8].value))
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[12].value) + ")")
try:
date = dacs.iso2DACS(str(row[14].value))
errorCount = dateCheck(str(row[14].value), errorCount, lineCount, row[8].value)
except:
errorCount += 1
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[14].value) + ") title: " + str(row[8].value))
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[14].value) + ")")
try:
date = dacs.iso2DACS(str(row[16].value))
errorCount = dateCheck(str(row[16].value), errorCount, lineCount, row[8].value)
except:
errorCount += 1
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[16].value) + ") title: " + str(row[8].value))
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[16].value) + ")")
try:
date = dacs.iso2DACS(str(row[18].value))
errorCount = dateCheck(str(row[18].value), errorCount, lineCount, row[8].value)
except:
errorCount += 1
try:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[18].value) + ") title: " + str(row[8].value))
except:
print ("Line " + str(lineCount) + ", DATE ERROR: (" + str(row[18].value) + ")")
if not row[22].value is None:
if len(str(row[22].value).strip()) > 0:
daoName = str(row[22].value).strip()
if not daoName.lower().startswith("http"):
if daoName in daoFileList:
errorCount += 1
print ("DAO ERROR: File listed twice (" + str(row[22].value) + ") line " + str(lineCount))
else:
daoFileList.append(daoName)
daoPath = os.path.join(__location__, "dao", daoName)
"""
if not os.path.isfile(daoPath):
errorCount += 1
print ("DAO ERROR: File Not Present in dao (" + str(row[22].value) + ") line " + str(lineCount))
"""
print (" " + str(errorCount) + " errors found in " + file)
# make sure console doesn't close
print ("Press Enter to continue...")
if sys.version_info >= (3, 0):
input()
else:
raw_input()