From 0efdfe66d5d1e70a418188913bf6883df60bf5c2 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 3 Aug 2023 11:48:03 +0300 Subject: [PATCH] recover from missing letter field --- parsers/caves.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/parsers/caves.py b/parsers/caves.py index 2bfd648..b68eee0 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -506,6 +506,14 @@ def read_cave(filename, cave=None): print(message) letter = getXML(e, "letter", maxItems=1, context=context)[0] + + if len(entrances) > 1 and letter =="": + # user error, but we can recover + letter = eslug[-1].lower() + message = f"- Warning - duplicate entrance or empty 'letter' field for '{eslug}' in cave '{cave}', setting to {letter}." + DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") + print(message) + if len(entrances) == 1 and not eslug: # may be empty: msg="DUMMY: no entrance slug read from file, so assume textually same as cave slug" set_dummy_entrance(slug[5:], slug, c, msg=msg) @@ -520,8 +528,8 @@ def read_cave(filename, cave=None): entrance = Entrance.objects.get(slug=eslug) entrances_xslug[eslug] = entrance except: - message = f"! eslug {eslug} Abort entrance loading. Failed to find entrance in db" - DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") + message = f"! Fail entrance loading {eslug} /entrance_data/{eslug} file does not exist or loading it failed." + DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") print(message) return @@ -530,6 +538,7 @@ def read_cave(filename, cave=None): DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") print(message) try: + # this fails if there is not an unambiguous letter set. CaveAndEntrance.objects.update_or_create( cave=cave, entrance_letter=letter, entrance=entrance )