diff options
Diffstat (limited to 'parsers/caves.py')
-rw-r--r-- | parsers/caves.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/parsers/caves.py b/parsers/caves.py index 745b119..514aa78 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -5,14 +5,15 @@ import re from django.conf import settings import troggle.core.models as models +import troggle.core.models_caves as models_caves def readcaves(): # Clear the cave data issues as we are reloading models.DataIssue.objects.filter(parser='caves').delete() - area_1623 = models.Area.objects.update_or_create(short_name = "1623", parent = None) - area_1626 = models.Area.objects.update_or_create(short_name = "1626", parent = None) + area_1623 = models_caves.Area.objects.update_or_create(short_name = "1623", parent = None) + area_1626 = models_caves.Area.objects.update_or_create(short_name = "1626", parent = None) print(" - Reading Entrances") #print "list of <Slug> <Filename>" for filename in next(os.walk(settings.ENTRANCEDESCRIPTIONS))[2]: #Should be a better way of getting a list of files @@ -23,6 +24,7 @@ def readcaves(): if filename.endswith('.html'): readcave(filename) + def readentrance(filename): with open(os.path.join(settings.ENTRANCEDESCRIPTIONS, filename)) as f: contents = f.read() @@ -54,7 +56,7 @@ def readentrance(filename): bearings = getXML(entrancecontents, "bearings", maxItems = 1, context = context) url = getXML(entrancecontents, "url", maxItems = 1, context = context) if len(non_public) == 1 and len(slugs) >= 1 and len(name) >= 1 and len(entrance_description) == 1 and len(explorers) == 1 and len(map_description) == 1 and len(location_description) == 1 and len(approach) == 1 and len(underground_description) == 1 and len(marking) == 1 and len(marking_comment) == 1 and len(findability) == 1 and len(findability_description) == 1 and len(alt) == 1 and len(northing) == 1 and len(easting) == 1 and len(tag_station) == 1 and len(exact_station) == 1 and len(other_station) == 1 and len(other_description) == 1 and len(bearings) == 1 and len(url) == 1: - e, state = models.Entrance.objects.update_or_create(name = name[0], + e, state = models_caves.Entrance.objects.update_or_create(name = name[0], non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]], entrance_description = entrance_description[0], explorers = explorers[0], @@ -81,7 +83,7 @@ def readentrance(filename): primary = True for slug in slugs: #print slug, filename - cs = models.EntranceSlug.objects.update_or_create(entrance = e, + cs = models_caves.EntranceSlug.objects.update_or_create(entrance = e, slug = slug, primary = primary) primary = False @@ -118,7 +120,7 @@ def readcave(filename): url = getXML(cavecontents, "url", maxItems = 1, context = context) entrances = getXML(cavecontents, "entrance", context = context) if len(non_public) == 1 and len(slugs) >= 1 and len(official_name) == 1 and len(areas) >= 1 and len(kataster_code) == 1 and len(kataster_number) == 1 and len(unofficial_number) == 1 and len(explorers) == 1 and len(underground_description) == 1 and len(equipment) == 1 and len(references) == 1 and len(survey) == 1 and len(kataster_status) == 1 and len(underground_centre_line) == 1 and len(notes) == 1 and len(length) == 1 and len(depth) == 1 and len(extent) == 1 and len(survex_file) == 1 and len(description_file ) == 1 and len(url) == 1 and len(entrances) >= 1: - c, state = models.Cave.objects.update_or_create(non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]], + c, state = models_caves.Cave.objects.update_or_create(non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]], official_name = official_name[0], kataster_code = kataster_code[0], kataster_number = kataster_number[0], @@ -139,17 +141,17 @@ def readcave(filename): url = url[0], filename = filename) for area_slug in areas: - area = models.Area.objects.filter(short_name = area_slug) + area = models_caves.Area.objects.filter(short_name = area_slug) if area: newArea = area[0] else: - newArea = models.Area(short_name = area_slug, parent = models.Area.objects.get(short_name = "1623")) + newArea = models_caves.Area(short_name = area_slug, parent = models_caves.Area.objects.get(short_name = "1623")) newArea.save() c.area.add(newArea) primary = True for slug in slugs: try: - cs = models.CaveSlug.objects.update_or_create(cave = c, + cs = models_caves.CaveSlug.objects.update_or_create(cave = c, slug = slug, primary = primary) except: @@ -162,8 +164,8 @@ def readcave(filename): slug = getXML(entrance, "entranceslug", maxItems = 1, context = context)[0] letter = getXML(entrance, "letter", maxItems = 1, context = context)[0] try: - entrance = models.Entrance.objects.get(entranceslug__slug = slug) - ce = models.CaveAndEntrance.objects.update_or_create(cave = c, entrance_letter = letter, entrance = entrance) + entrance = models_caves.Entrance.objects.get(entranceslug__slug = slug) + ce = models_caves.CaveAndEntrance.objects.update_or_create(cave = c, entrance_letter = letter, entrance = entrance) except: message = " ! Entrance text (slug) %s missing %s" % (slug, context) models.DataIssue.objects.create(parser='caves', message=message) @@ -185,4 +187,4 @@ def getXML(text, itemname, minItems = 1, maxItems = None, printwarnings = True, "max": maxItems} + context models.DataIssue.objects.create(parser='caves', message=message) print(message) - return items + return items
\ No newline at end of file |