summaryrefslogtreecommitdiffstats
path: root/parsers/caves.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-09-15 22:41:40 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-09-15 22:41:40 +0300
commita8d4b05617f4ef42687bc0354e2940226ab6987f (patch)
tree9e93bae64c8552c26b1b9445d823a0f59c8ed231 /parsers/caves.py
parent3390f17aa4b96827f2bdedf7eb4eab8773e7bfa6 (diff)
downloadtroggle-a8d4b05617f4ef42687bc0354e2940226ab6987f.tar.gz
troggle-a8d4b05617f4ef42687bc0354e2940226ab6987f.tar.bz2
troggle-a8d4b05617f4ef42687bc0354e2940226ab6987f.zip
finding the right survex file for a cave
Diffstat (limited to 'parsers/caves.py')
-rw-r--r--parsers/caves.py51
1 files changed, 39 insertions, 12 deletions
diff --git a/parsers/caves.py b/parsers/caves.py
index e7eebb4..391501e 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -1,7 +1,7 @@
import os
import re
import string
-
+import sys
from pathlib import Path
@@ -103,15 +103,37 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"):
# print(message)
-def create_new_cave(svxpath, msg=None):
+def create_new_cave(svxpath, svxid=None, 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/beast" .svx
+ # e.g. svxpath = "caves-1623/666/beast" .svx - from the *inlcude tree
+ # e.g. svxid = "caves-1623/666/beast"
print(f"Create new cave at {svxpath} - {msg}")
#
- survex_file = svxpath.replace("caves-","") + ".svx"
+ survex_file = ""
+ if svxid:
+ sv = Path(settings.SURVEX_DATA, svxid + ".svx")
+ if sv.is_file:
+ survex_file = svxid + ".svx"
+ else:
+ sv = Path(settings.SURVEX_DATA, svxpath + ".svx")
+ if sv.is_file:
+ survex_file = svxpath + ".svx"
+
+ if survex_file:
+ # message = f"Found a survex file {survex_file=} {svxpath=} {svxid=} "
+ # DataIssue.objects.create(parser="caves", message=message)
+ # print(message, file=sys.stderr)
+ # print(message)
+ pass
+ else:
+ message = f"NOT found a survex file {svxpath=} {svxid=}"
+ DataIssue.objects.create(parser="caves", message=message)
+ print(message, file=sys.stderr)
+ print(message)
+
parts = svxpath.split("/")
a = parts[0][-4:]
caveid = parts[1]
@@ -142,9 +164,8 @@ def create_new_cave(svxpath, msg=None):
print(message)
raise
- # we know what the survex file is, we don't need to use the guess.
- # But this sets the survex file on the cave from the first one we find, not necessarily the best survex file for this cave
- cave.survex_file=survex_file
+ # But this sets the survex file on the Cave from the first one we find, not necessarily the best survex file for this cave
+ cave.survex_file=survex_file # primary survex file for Cave
cave.areacode=areacode
cave.save()
return cave
@@ -230,6 +251,9 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
"""Guesses at and finds a survex file for this pending cave.
Convoluted. Needs rewriting.
Pointless if this cave is being created because we found a survex file...
+
+ On problem is that the Cave name may have different capitalisation from the survex filename,
+ e.g. 2018-NTU-02 has a survex file 2018-ntu-02.svx
"""
if k[0:3] == "162":
id = Path(k[5:])
@@ -244,6 +268,7 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
if Path(settings.SURVEX_DATA, survex_file).is_file():
return survex_file
+ # This should find the file even if the capitalisation is different, or if the directory name is totaly different
survex_file = ""
d = Path(settings.SURVEX_DATA, f"caves-{areacode}/{id}")
if d.is_dir():
@@ -257,10 +282,12 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
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} - {msg}"
- # DataIssue.objects.create(parser='caves', message=message, url=url)
- # print(message)
- return 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)
+ if Path(settings.SURVEX_DATA, survex_file).is_file():
+ return survex_file
+ return ""
g = GetCaveLookup()
with transaction.atomic():
@@ -324,7 +351,7 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
)
if cave:
cave.save() # must save to have id before foreign keys work. This is also a ManyToMany key.
- message = f" ! {slug:18} Pending cave write-up url: {url} - {msg}"
+ message = f" ! {slug:18} Pending cave write-up url: {url} - {survex_file=} - {msg}"
DataIssue.objects.create(parser="caves", message=message, url=url)
print(message)