diff options
Diffstat (limited to 'parsers/caves.py')
-rw-r--r-- | parsers/caves.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/parsers/caves.py b/parsers/caves.py index 982fb40..abeb800 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -130,13 +130,13 @@ def get_area(areanum): area = Area.objects.get(short_name="1627") return area -def create_new_cave(svxpath): +def create_new_cave(svxpath, msg=None): """This is called only when a new survex file is edited online which has a path on the :loser: repo which is not recognised as a known cave. ALSO called by survex parser when it finds a cave it doesn't recognise """ # e.g. svxpath = "caves-1623/666/antig" - print(f"Create new cave at {svxpath}") + print(f"Create new cave at {svxpath} - {msg}") # survex_file = svxpath + ".svx" parts = svxpath.split("/") @@ -149,7 +149,7 @@ def create_new_cave(svxpath): url = f"{areanum}/{caveid}.html" # Note we are appending the .html as we are believe in backwards compatability. #url = f"{areanum}/{a[5:]}.html" # This is original code, but a above is only defined as being 4 characters long, so it did not make sense and produced non unique urls else: - print(f"WARNING: parsers/caves/create_new_cave called with svxpath '{svxpath}'. Surely it should start 'caves-162*'?") + print(f"WARNING: parsers/caves/create_new_cave called with svxpath '{svxpath}'. Surely it should start 'caves-162*'? {msg}") areanum = "1623" url = f"1623/{caveid}.html" #url = f"1623/{k}.html" # This is original code, but a above is only defined as being 4 characters long, so it did not make sense and produced non unique urls @@ -157,17 +157,17 @@ def create_new_cave(svxpath): k = f"{areanum}-{caveid}" area = get_area(areanum) - caves = Cave.objects.filter(unofficial_number=caveid) + caves = Cave.objects.filter(unofficial_number=caveid, area =areanum) if caves: - message = f" ! Already exists, caveid:{k} in area {areanum} {caves}" + message = f" ! Already exists, caveid:{k} in area {areanum} {caves} - {msg}" DataIssue.objects.create(parser="caves", message=message) print(message) return caves[0] try: - cave = do_pending_cave(k, caveid, url, area) + cave = do_pending_cave(k, caveid, url, area, msg) except: - message = f" ! Error. Cannot create pending cave and entrance, pending-id:{k} in area {areanum}" + message = f" ! Error. Cannot create pending cave and entrance, pending-id:{k} in area {areanum} - {msg}" DataIssue.objects.create(parser="caves", message=message) print(message) raise @@ -178,7 +178,7 @@ def create_new_cave(svxpath): cave.save() return cave -def do_pending_cave(k, caveid, url, area): +def do_pending_cave(k, caveid, url, area, msg=None): """ default for a PENDING cave, should be overwritten in the db later if a real cave of the same name exists in expoweb/cave_data/1623-"k".html @@ -217,7 +217,7 @@ def do_pending_cave(k, caveid, url, area): prime_suspect = survex_file if prime_suspect: survex_file = prime_suspect - # message = f" ! {k:14} Found a survex file which might be the right one: {survex_file}" + # message = f" ! {k:14} Found a survex file which might be the right one: {survex_file} - {msg}" # DataIssue.objects.create(parser='caves', message=message, url=url) # print(message) return survex_file @@ -227,7 +227,7 @@ def do_pending_cave(k, caveid, url, area): g = GetCaveLookup() with transaction.atomic(): if slug in g: - message = f" ! {k:18} cave listed in pendingcaves.txt already exists." + message = f" ! {k:18} cave listed in pendingcaves.txt already exists. - {msg}" DataIssue.objects.create(parser="caves", message=message, url=url) print(message) return @@ -267,11 +267,17 @@ def do_pending_cave(k, caveid, url, area): default_note += ( f"to remove the line <br><var>{slug}</var><br> as it is no longer 'pending' but 'done. Well Done." ) + urltest = Cave.objects.filter(url=url) + if urltest: + message = f" ! Cave {urltest[0]} already exists with this url {url}. Can't create new cave {slug}" + DataIssue.objects.create(parser="caves", message=message, url=url) + print(message) + return urltest[0] survex_file = get_survex_file(k) cave = Cave( - unofficial_number=caveid, + unofficial_number=caveid.upper(), underground_description="Pending cave write-up - No cave description created yet.", survex_file=survex_file, url=url, @@ -281,30 +287,21 @@ def do_pending_cave(k, caveid, url, area): cave.save() # must save to have id before foreign keys work. This is also a ManyToMany key. cave.area.add(area) cave.save() - message = f" ! {k:18} {cave.underground_description} url: {url}" + message = f" ! {k:18} Pending cave write-up url: {url} - {msg}" DataIssue.objects.create(parser="caves", message=message, url=url) print(message) try: # Now create a cave slug ID CaveSlug.objects.update_or_create(cave=cave, slug=slug, primary=False) except: - message = f" ! {k:11s} PENDING CaveSLUG {slug} create failure" + message = f" ! {k:11s} PENDING CaveSLUG {slug} create failure - {msg}" DataIssue.objects.create(parser="caves", message=message) print(message) else: - message = f" ! {k:11s} PENDING cave create failure" + message = f" ! {k:11s} PENDING cave create failure - {msg}" DataIssue.objects.create(parser="caves", message=message) print(message) - try: - # troggle is more robust against missing entrances now, not needed. - # set_dummy_entrance(k, slug, cave, msg="PENDING") - pass - except: - message = f" ! {k:11s} PENDING entrance + cave UNION create failure '{cave}' [{slug}] {k}" - # message = f" ! {k:11s} PENDING entrance + cave UNION create failure '{cave}' [{ent}]" - DataIssue.objects.create(parser="caves", message=message) - print(message) return cave def getXML(text, itemname, minItems=1, maxItems=None, context=""): @@ -730,7 +727,9 @@ def read_cave(filename, cave=None): cave.save() return cave -def add_cave_to_pending_list(id): +def add_cave_to_pending_list(id, msg=None): + message = f"On dev machine, adding to PENDING. - {msg}" + print(message) fpending = Path(CAVEDESCRIPTIONS, "pendingcaves.txt") try: if settings.DBSWITCH == "sqlite": # dev machine only |