more QMs parsed correctly

This commit is contained in:
2023-03-18 00:57:40 +00:00
parent 7345e3a328
commit d64948749e
4 changed files with 36 additions and 25 deletions

View File

@@ -141,16 +141,26 @@ def parse_KH_QMs(kh, inputFile, ticked):
with open(os.path.join(settings.EXPOWEB, inputFile), "r") as khQMfile:
khQMs = khQMfile.readlines()
nqms = 0
for line in khQMs:
line = 0
fails = 0
for dataline in khQMs:
# <dt><a href="sibria.htm#qC1997-161-27" name="C1997-161-27">C1997-161-27</a> A<dd>Sib: pitch at end of Fuzzy Logic [Paradox Rift - continues] [sep.fuzzy.13]
line += 1
res = re.search(
r"name=\"[CB](?P<year>\d*)-(?P<cave>\d*)-(?P<number>\d*).*</a> (?P<grade>[ABCDX])<dd>(?P<location_description>.*)\[(?P<nearest_station_name>.*)\]",
line,
r"name=\"[CB](?P<year>\d*)-(?P<cave>\d*)-(?P<number>\d*).*</a>\s*(?P<grade>[ABCDX?V])<dd>(?P<location_description>.*)(\[(?P<station_name>.*)\])?",
dataline,
)
if res:
res = res.groupdict()
year = int(res["year"])
nearest_station_name = ""
resolution_station_name = ""
if res["station_name"]:
if ticked:
resolution_station_name = res["station_name"].replace("<a href=\"","<a href=\"/1623/161/")
else:
nearest_station_name = res["station_name"]
lookupAttribs = {
#'found_by':placeholder,
"blockname": "",
@@ -163,13 +173,20 @@ def parse_KH_QMs(kh, inputFile, ticked):
"ticked": ticked,
"page_ref": "",
"completion_description": "",
"nearest_station_name": res["nearest_station_name"],
"location_description": res["location_description"],
"nearest_station_name": nearest_station_name,
"resolution_station_name": resolution_station_name,
"location_description": res["location_description"].replace("<a href=\"","<a href=\"/1623/161/"),
}
# Create new. We know it doesn't exist as we deleted evrything when we started.
instance = QM.objects.create(**nonLookupAttribs, **lookupAttribs)
nqms += 1
else:
if dataline.startswith("<dt><a href"):
fails += 1
message = f" ! - {inputFile} line {line} Parse error \n{str(dataline)} "
print(message)
DataIssue.objects.create(parser="QMs", message=message)
print(f" - {fails:2g} parsing errors in {inputFile}")
return nqms