summaryrefslogtreecommitdiffstats
path: root/parsers/QMs.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-03-18 00:57:40 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-03-18 00:57:40 +0000
commitd64948749e2f963f1938016764ce8256efd796dd (patch)
treefc23226929a54f2eea765d04a55d3eeddc38c9ab /parsers/QMs.py
parent7345e3a3286ebf2771a7c7800c83632cc9930fa1 (diff)
downloadtroggle-d64948749e2f963f1938016764ce8256efd796dd.tar.gz
troggle-d64948749e2f963f1938016764ce8256efd796dd.tar.bz2
troggle-d64948749e2f963f1938016764ce8256efd796dd.zip
more QMs parsed correctly
Diffstat (limited to 'parsers/QMs.py')
-rw-r--r--parsers/QMs.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/parsers/QMs.py b/parsers/QMs.py
index f3044ff..5a0be79 100644
--- a/parsers/QMs.py
+++ b/parsers/QMs.py
@@ -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