diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2020-07-04 01:10:53 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2020-07-04 01:10:53 +0100 |
commit | 51d0daafdd6d1a41874eb4a797da1619960388ff (patch) | |
tree | da6405d558b1fb844fadb9c758991f554b8c9043 /parsers/QMs.py | |
parent | 5ed6271c086277b08982136c3433e544a5b4d4fe (diff) | |
download | troggle-51d0daafdd6d1a41874eb4a797da1619960388ff.tar.gz troggle-51d0daafdd6d1a41874eb4a797da1619960388ff.tar.bz2 troggle-51d0daafdd6d1a41874eb4a797da1619960388ff.zip |
QM placeholder logbook entries sorted out
Diffstat (limited to 'parsers/QMs.py')
-rw-r--r-- | parsers/QMs.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/parsers/QMs.py b/parsers/QMs.py index d96b665..89a2640 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -12,9 +12,21 @@ from utils import save_carefully def deleteQMs(): QM.objects.all().delete() + DataIssue.objects.filter(parser='QMs').delete() + def parseCaveQMs(cave,inputFile): - """Runs through the CSV file at inputFile (which is a relative path from expoweb) and saves each QM as a QM instance.""" + """Runs through the CSV file at inputFile (which is a relative path from expoweb) and + saves each QM as a QM instance. + This is creating and linking a Placeholder logbookentry dated 1st Jan. in the relevant + year. This is pointless but it is needed because found_by is a ForeignKey in the db + and we can't be arsed to fudge this properly with a null.(July 2020) + + Linking to a passage in a SVX file might be more interesting as the QM does sometimes + have the passage name, e.g. in 204/qm.csv + C2000-204-39 B Tree Pitch in Cave Tree treeumphant.28 Gosser Streamway + The CSV file does not have the exact date for the QM, only the year, so links to + survex files might be ambiguous. But potentially useful?""" if cave=='204-steinBH': try: @@ -51,9 +63,9 @@ def parseCaveQMs(cave,inputFile): placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr)}) elif cave=='234-Hauch': placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)}) - if hadToCreate: - print(message) - DataIssue.objects.create(parser='QMs', message=message) + # if hadToCreate: + # print(message) + # DataIssue.objects.create(parser='QMs', message=message) QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb") newQM = QM() newQM.found_by=placeholder @@ -65,9 +77,11 @@ def parseCaveQMs(cave,inputFile): newQM.area=line[2] newQM.location_description=line[3] + # Troggle checks if QMs are completed by checking if they have a ticked_off_by trip. + # In the table, completion is indicated by the presence of a completion discription. newQM.completion_description=line[4] newQM.nearest_station_description=line[5] - if newQM.completion_description: # Troggle checks if QMs are completed by checking if they have a ticked_off_by trip. In the table, completion is indicated by the presence of a completion discription. + if newQM.completion_description: newQM.ticked_off_by=placeholder newQM.comment=line[6] @@ -76,18 +90,16 @@ def parseCaveQMs(cave,inputFile): if preexistingQM.new_since_parsing==False: #if the pre-existing QM has not been modified, overwrite it preexistingQM.delete() newQM.save() - #print((" - overwriting " + str(preexistingQM) +"\r")) else: # otherwise, print that it was ignored print((" - preserving " + str(preexistingQM) + ", which was edited in admin \r")) except QM.DoesNotExist: #if there is no pre-existing QM, save the new one newQM.save() - # print("QM "+str(newQM) + ' added to database\r') except KeyError: #check on this one continue except IndexError: - print(("Index error in " + str(line))) + print("Index error in " + str(line)) continue def parse_KH_QMs(kh, inputFile): @@ -103,9 +115,9 @@ def parse_KH_QMs(kh, inputFile): #check if placeholder exists for given year, create it if not message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. Should be re-attached to the actual trip." placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)}) - if hadToCreate: - print(message) - DataIssue.objects.create(parser='QMs', message=message) + # if hadToCreate: + # print(message) + # DataIssue.objects.create(parser='QMs', message=message) lookupArgs={ 'found_by':placeholder, 'number':res['number'] @@ -119,6 +131,7 @@ def parse_KH_QMs(kh, inputFile): save_carefully(QM,lookupArgs,nonLookupArgs) def Load_QMs(): + deleteQMs() parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv") parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv") parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm") |