diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:24:37 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:24:37 +0100 |
commit | 8c818906b5c1228a6fb411cb96d1bd5f1663b49a (patch) | |
tree | 29e5d099b102f2a61fe40288fc5415ba8bf8e70e /parsers/QMs.py | |
parent | 1d8f647699a3f5f489f46dba595e03fc613cb4e3 (diff) | |
download | troggle-8c818906b5c1228a6fb411cb96d1bd5f1663b49a.tar.gz troggle-8c818906b5c1228a6fb411cb96d1bd5f1663b49a.tar.bz2 troggle-8c818906b5c1228a6fb411cb96d1bd5f1663b49a.zip |
[svn] Added QM model and parser. Had to merge models_cave.py and models_logbooks.py into models.py. This is because logbook entries now have an optional foreign key to caves, and QMs have a required foreign key to a logbook entry of the trip that created them. So, the two files became circularly dependent.
Also, the urls for the person model now allow lookups using their actual first and last name in the url instead of the primary key. We should do similar things for all models, maybe even using the url as a search which results in a page with multiple model instance results if the input is ambiguous (e.g. they only enter a first name).
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8093 by aaron @ 12/13/2008 11:17 PM
Diffstat (limited to 'parsers/QMs.py')
-rw-r--r-- | parsers/QMs.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/parsers/QMs.py b/parsers/QMs.py new file mode 100644 index 0000000..44c38c7 --- /dev/null +++ b/parsers/QMs.py @@ -0,0 +1,36 @@ +import csv +import settings +from expo.models import QM, LogbookEntry, Cave +from datetime import * +import re + +#sorry that the below code is ugly. I'll fix it sometime, really! - AC + +QM.objects.all().delete() + + + +def parseSteinbrQMs(): + try: + steinBr=Cave.objects.get(official_name="Steinbrückenhöhle") + except Cave.DoesNotExist: + print "Steinbruckenhoehle is not in the database. Please run parsers.cavetab first." + return + + + qmPath = settings.EXPOWEB+r"smkridge/204/qm.csv" + qmReader = csv.reader(open(qmPath,'r'),dialect="excel-tab") + qmReader.next() # Skip header row + for line in qmReader: + year=int(line[0][1:5]) + + #check if placeholder exists for given year, create it if not + placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, text="placeholder for QMs in 204", defaults={"date": date(year, 1, 1),"cave":steinBr}) + if hadToCreate: + print "204 placeholder logbook entry for " + str(year) + " added to database" + QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb") + newQM = QM(found_by=placeholder,number=QMnum,grade=line[1],area=line[2],location_description=line[3],nearest_station_description=line[4],completion_description=line[5],comment=line[6]) + newQM.save() + print "QM "+str(newQM) + " added to database" + +parseSteinbrQMs()
\ No newline at end of file |