diff --git a/parsers/survex.py b/parsers/survex.py index 25bb028..405771d 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -695,12 +695,15 @@ class LoadingSurvex: ) oline = line + perps = get_people_on_trip(survexblock) # What, you don't know Judge Dredd slang ? + if len(line) > 10: message = "! DATE Warning LONG DATE '{}' ({}) {}".format(oline, survexblock, survexblock.survexfile.path) print(self.insp+message) stash_data_issue(parser='svxdate', message=message, url=None, sb=(survexblock.survexfile.path)) if line[10] == "-": # ie a range, just look at first date line = line[0:10] + if len(line) == 10: year = line[:4] # TO DO set to correct Austrian timezone Europe/Vienna ? @@ -708,7 +711,6 @@ class LoadingSurvex: survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d") elif len(line) == 7: year = line[:4] - perps = get_people_on_trip(survexblock) # What, you don't know Judge Dredd slang ? message = f"! DATE Warning only accurate to the month, setting to 1st '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}" print(self.insp + message) stash_data_issue( @@ -717,13 +719,36 @@ class LoadingSurvex: survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m") # sets to first of month elif len(line) == 4: year = line[:4] - perps = get_people_on_trip(survexblock) message = f"! DATE WARNING only accurate to the YEAR, setting to 1st January '{oline}' ({survexblock}) {survexblock.survexfile.path} {perps}" print(self.insp + message) stash_data_issue( parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path) ) survexblock.date = datetime.strptime(line, "%Y") # sets to January 1st + elif len(line) == 9 or len(line) == 8: + year = line[:4] + message = f"! DATE format WARNING, single digit day or month number,'{oline}' [{line[-5]}][{line[-2]}] ({survexblock}) {survexblock.survexfile.path}" + print(self.insp + message) + stash_data_issue( + parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path) + ) + if line[-2] == "-" or line[-2] == ".": + line = line[:-1] + '0' + line[-1] + survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d") + print(f"! DATE -2 '{line}' '{survexblock.date}'") + elif line[-5] == "-" or line[-5] == ".": + line = line[:-4] + '0' + line[-4:] + survexblock.date = datetime.strptime(line.replace(".", "-"), "%Y-%m-%d") + print(f"! DATE -5 '{line}' '{survexblock.date}'") + else: + year = line[:4] + message = ( + f"! DATE Error SHORT LINE '{line}' '{oline}-{survexblock}' ({type(survexblock)}) {survexblock.survexfile.path}" + ) + print(self.insp + message) + stash_data_issue( + parser="svxdate", message=message, url=None, sb=(survexblock.survexfile.path) + ) else: # these errors are reporting the wrong survexblock, which is actually a SurvexFile (!) # see To Do notes on how to trigger this. Still needs investigating.. @@ -737,13 +762,16 @@ class LoadingSurvex: print(f" {type(survexblock)=}") # survexblock.parent fails as a SurvexFile has no .parent ...ugh. print(f" {survexblock.survexpath=}") print(f" {survexblock.survexfile=}") + # Not setting 'year' crashes entire import on databaseReset. + year = line[:4] + perps = get_people_on_trip(survexblock) # raise try: setdate_on_survexblock(year) except NameError: - print(">> why is year not set ?! {survexblock.survexfile.path}") - setdate_on_survexblock("1970") + print(f">> why is year not set ?! {survexblock.survexfile.path}") + setdate_on_survexblock("1976") if survexblock.date: # do not actually need a distict variable 'currentdate' but it makes the code clearer self.currentdate = survexblock.date @@ -1383,8 +1411,8 @@ class LoadingSurvex: self.fix_undated(survexblock) # null-op if already set try: expoyear = str(survexblock.date.year) - except NameError: - print(">> why is survexblock.date.year not set ?! in LoadSurvexQM()/n {survexblock.survexfile.path}") + except: + print(f">> why is survexblock not set ?! in LoadSurvexQM()/n {survexblock.survexfile.path}") expoyear = "1970"