summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-08-11 13:29:30 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2024-08-11 13:29:30 +0300
commit89ef1afbe856dc5a2c25c871d810fe549ef89a20 (patch)
treec8dbe1b65c143914524227ed2837669431c69e2d
parent1203b5153069371abb0df0e71352c9a925de223b (diff)
downloadtroggle-89ef1afbe856dc5a2c25c871d810fe549ef89a20.tar.gz
troggle-89ef1afbe856dc5a2c25c871d810fe549ef89a20.tar.bz2
troggle-89ef1afbe856dc5a2c25c871d810fe549ef89a20.zip
check slashes in dates in wallets
-rw-r--r--core/models/wallets.py13
-rw-r--r--parsers/logbooks.py2
2 files changed, 10 insertions, 5 deletions
diff --git a/core/models/wallets.py b/core/models/wallets.py
index ba997ab..4077961 100644
--- a/core/models/wallets.py
+++ b/core/models/wallets.py
@@ -18,10 +18,10 @@ from troggle.core.models.caves import get_cave_leniently
YEAR_RANGE = (1975, 2050)
-def make_valid_date(date):
+def make_valid_date(walletname, date):
"""Take whatever garbage some fool has typed in and try to make it into a valid ISO-format date
"""
- datestr = date.replace(".", "-")
+ datestr = date.replace(".", "-").replace("/", "-")
try:
samedate = datetime.date.fromisoformat(datestr)
return samedate
@@ -36,7 +36,7 @@ def make_valid_date(date):
y = y + 2000
try:
samedate = datetime.date(y, m, d)
- print(f"- - Warning, not in ISO format. '{datestr=}' but we coped: {samedate.isoformat()} ")
+ print(f"- - Warning, not in ISO format. '{datestr=}' but we tried to cope: {samedate.isoformat()} {walletname}")
return samedate
except:
print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ")
@@ -150,9 +150,14 @@ class Wallet(models.Model):
# :drawings: walletjson/2022/2022#01/contents.json
# fpath = /mnt/d/EXPO/expofiles/surveyscans/1999/1999#02
+ # This does not work if there are subdirectories in the surveyscan folder
fp = Path(self.fpath)
wname = fp.name
wyear = fp.parent.name
+
+ if not int(wyear):
+ message = f"! Subfolder detected?:\n {wyear=} (should be eg. '2023')\n {wname=} \n {self.fpath=}"
+ print(message)
wurl = self.get_url()
if len(wyear) != 4 or len(wname) !=6:
@@ -180,7 +185,7 @@ class Wallet(models.Model):
return None
if waldata["date"]:
- thisdate = make_valid_date(waldata["date"])
+ thisdate = make_valid_date(self.walletname, waldata["date"])
if thisdate:
self.walletdate = thisdate
self.save()
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index 8950dac..5f3805a 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -59,7 +59,7 @@ LOGBOOK_PARSER_SETTINGS = {
LOGBOOKS_DIR = "years" # subfolder of settings.EXPOWEB
ENTRIES = {
- "2024": 104,
+ "2024": 113,
"2023": 131,
"2022": 94,
"2019": 55,