2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

check slashes in dates in wallets

This commit is contained in:
Philip Sargent 2024-08-11 13:29:30 +03:00
parent 1203b51530
commit 89ef1afbe8
2 changed files with 10 additions and 5 deletions

View File

@ -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()

View File

@ -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,