diff options
author | Martin Green <martin.speleo@gmail.com> | 2012-06-10 14:59:21 +0100 |
---|---|---|
committer | Martin Green <martin.speleo@gmail.com> | 2012-06-10 14:59:21 +0100 |
commit | 711fefb0da7b4a744c71f3d1648d3398c401f4fc (patch) | |
tree | d3fbeeb25593d70bb276f0173807490f7ba91d1d /parsers/cavetab.py | |
parent | fd12e70f7818f42f7f569576369dec287fec7ccc (diff) | |
download | troggle-711fefb0da7b4a744c71f3d1648d3398c401f4fc.tar.gz troggle-711fefb0da7b4a744c71f3d1648d3398c401f4fc.tar.bz2 troggle-711fefb0da7b4a744c71f3d1648d3398c401f4fc.zip |
Start to change dataformat for caves, along with there editing. Start to change survex reader to cope better with equates/tags.
Diffstat (limited to 'parsers/cavetab.py')
-rw-r--r-- | parsers/cavetab.py | 143 |
1 files changed, 77 insertions, 66 deletions
diff --git a/parsers/cavetab.py b/parsers/cavetab.py index d76a280..9f04105 100644 --- a/parsers/cavetab.py +++ b/parsers/cavetab.py @@ -108,14 +108,15 @@ def LoadCaveTab(): addToDefaultArgs(AutogenFile, "url") if line[Area] == "1626": if line[KatasterNumber] != "": - args["slug"] = line[Area] + "-" + line[KatasterNumber] + slug = line[Area] + "-" + line[KatasterNumber] else: - args["slug"] = line[Area] + "-" + line[UnofficialNumber] + slug = line[Area] + "-" + line[UnofficialNumber] else: if line[KatasterNumber] != "": - args["slug"] = "1623" + "-" + line[KatasterNumber] + slug = "1623" + "-" + line[KatasterNumber] else: - args["slug"] = "1623" + "-" + line[UnofficialNumber] + slug = "1623" + "-" + line[UnofficialNumber] + args["filename"] = "%s.html" % slug #The following adds the legacy_file_path. This is always in either Autogen file or Link file for header in (AutogenFile,LinkFile): if line[header]: @@ -126,8 +127,9 @@ def LoadCaveTab(): #Noinfo was the name of the old password protected directory, so if it has that then we will #set the non_public field of the model instance to true. defaultArgs["non_public"]=line[AutogenFile].startswith('noinfo') or line[LinkFile].startswith('noinfo') - - newCave, created=save_carefully(models.Cave, lookupAttribs=args, nonLookupAttribs=defaultArgs) + newCave, created = save_carefully(models.Cave, lookupAttribs=args, nonLookupAttribs=defaultArgs) + cs = models.CaveSlug(slug = slug, cave = newCave, primary = True) + cs.save() logging.info("Added cave "+str(newCave)+"\n") #If we created a new cave, add the area to it. This does mean that if a cave's identifying features have not changed, areas will not be updated from csv. @@ -148,8 +150,7 @@ def LoadCaveTab(): newCave.save() - logging.info("Added area "+line[Area]+" to cave "+str(newCave)+"\n") - + logging.info("Added area "+line[Area]+" to cave "+str(newCave)+"\n") if created and line[UnofficialName]: newUnofficialName = models.OtherCaveName(cave = newCave, name = line[UnofficialName]) newUnofficialName.save() @@ -161,70 +162,80 @@ def LoadCaveTab(): line[MultipleEntrances] == 'entrance' or \ line[MultipleEntrances] == 'last entrance': args = {} - - if line[Entrances]: - entrance_letter = line[Entrances] - else: - entrance_letter = '' - def addToArgs(CSVname, modelName): if line[CSVname]: args[modelName] = line[CSVname] def addToArgsViaDict(CSVname, modelName, dictionary): if line[CSVname]: args[modelName] = dictionary[line[CSVname]] - addToArgs(EntranceName, 'name') - addToArgs(Explorers, 'explorers') - addToArgs(Map, 'map_description') - addToArgs(Location, 'location_description') - addToArgs(Approach, 'approach') - addToArgs(EntranceDescription, 'entrance_description') - addToArgs(UndergroundDescription, 'underground_description') - addToArgs(PhotoOfLocation, 'photo') - addToArgsViaDict(Marking, 'marking', {"Paint": "P", - "Paint (?)": "P?", - "Tag": "T", - "Tag (?)": "T?", - "Retagged": "R", - "Retag": "R", - "Spit": "S", - "Spit (?)": "S?", - "Unmarked": "U", - "": "?", - }) - - addToArgs(MarkingComment, 'marking_comment') - addToArgsViaDict(Findability, 'findability', {"Surveyed": "S", - "Lost": "L", - "Refindable": "R", - "": "?", - "?": "?", - }) - addToArgs(FindabilityComment, 'findability_description') - addToArgs(Easting, 'easting') - addToArgs(Northing, 'northing') - addToArgs(Altitude, 'alt') - addToArgs(DescriptionOfOtherPoint, 'other_description') - addToArgs(TagPoint, 'tag_station') - addToArgs(ExactEntrance, 'exact_station') - addToArgs(OtherPoint, 'other_station') - addToArgs(OtherPoint, 'other_description') - if line[GPSpreSA]: - addToArgs(GPSpreSA, 'other_station') - args['other_description'] = 'pre selective availability GPS' - if line[GPSpostSA]: - addToArgs(GPSpostSA, 'other_station') - args['other_description'] = 'post selective availability GPS' - addToArgs(Bearings, 'bearings') - args['slug'] = newCave.slug + entrance_letter - newEntrance = models.Entrance(**args) - newEntrance.save() - - logging.info("Added entrance "+str(newEntrance)+"\n") - - - newCaveAndEntrance = models.CaveAndEntrance(cave = newCave, entrance = newEntrance, entrance_letter = entrance_letter) - newCaveAndEntrance.save() + + if line[Entrances]: + entrance_letter = line[Entrances] + else: + entrance_letter = '' + + if not line[LinkFile]: + addToArgs(Map, 'map_description') + addToArgs(Location, 'location_description') + addToArgs(Approach, 'approach') + addToArgs(EntranceDescription, 'entrance_description') + if line[MultipleEntrances] == 'entrance' or \ + line[MultipleEntrances] == 'last entrance': + addToArgs(UndergroundDescription, 'underground_description') + addToArgs(AutogenFile, 'url') + addToArgs(EntranceName, 'name') + addToArgs(Explorers, 'explorers') + addToArgs(PhotoOfLocation, 'photo') + addToArgsViaDict(Marking, 'marking', {"Paint": "P", + "Paint (?)": "P?", + "Tag": "T", + "Tag (?)": "T?", + "Retagged": "R", + "Retag": "R", + "Spit": "S", + "Spit (?)": "S?", + "Unmarked": "U", + "": "?", + }) + + addToArgs(MarkingComment, 'marking_comment') + addToArgsViaDict(Findability, 'findability', {"Surveyed": "S", + "Lost": "L", + "Refindable": "R", + "": "?", + "?": "?", + }) + addToArgs(FindabilityComment, 'findability_description') + addToArgs(Easting, 'easting') + addToArgs(Northing, 'northing') + addToArgs(Altitude, 'alt') + addToArgs(DescriptionOfOtherPoint, 'other_description') + addToArgs(TagPoint, 'tag_station') + addToArgs(ExactEntrance, 'exact_station') + addToArgs(OtherPoint, 'other_station') + addToArgs(OtherPoint, 'other_description') + if line[GPSpreSA]: + addToArgs(GPSpreSA, 'other_station') + args['other_description'] = 'pre selective availability GPS' + if line[GPSpostSA]: + addToArgs(GPSpostSA, 'other_station') + args['other_description'] = 'post selective availability GPS' + addToArgs(Bearings, 'bearings') + args["filename"] = "%s.html" % (slug + entrance_letter) + + newEntrance = models.Entrance(**args) + newEntrance.save() + es = models.EntranceSlug(slug = slug + entrance_letter, entrance = newEntrance, primary = True) + es.save() + + + logging.info("Added entrance "+str(newEntrance)+"\n") + + + newCaveAndEntrance = models.CaveAndEntrance(cave = newCave, + entrance = newEntrance, + entrance_letter = entrance_letter) + newCaveAndEntrance.save() logging.info("Added CaveAndEntrance "+str(newCaveAndEntrance)+"\n") if line[AutogenFile] != "": |