2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-14 16:19:46 +00:00

Removing foissil: subcave and flatpages-redirects

This commit is contained in:
Philip Sargent
2020-07-22 22:14:35 +01:00
parent 190514597b
commit 427afa9ebd
8 changed files with 85 additions and 83 deletions

View File

@@ -57,7 +57,8 @@ def import_drawingsfiles():
print("-- Importing Drawings files")
troggle.parsers.surveys.LoadDrawingFiles()
def import_subcaves():
print("-- Interpreting SubCaves from CaveDescriptions")
troggle.parsers.subcaves.importAllSubcaves()
# Fossil.
# def import_subcaves():
# print("-- Interpreting SubCaves from CaveDescriptions")
# troggle.parsers.subcaves.importAllSubcaves()

View File

@@ -1,60 +1,60 @@
'''
This module is the part of troggle that parses descriptions of cave parts (subcaves) from the legacy html files and saves them in the troggle database as instances of the model Subcave. Unfortunately, this parser can not be very flexible because the legacy format is poorly structured.
'''
import sys
import os
import re
import logging
# '''
# This module is the part of troggle that parses descriptions of cave parts (subcaves) from the legacy html files and saves them in the troggle database as instances of the model Subcave. Unfortunately, this parser can not be very flexible because the legacy format is poorly structured.
# '''
# import sys
# import os
# import re
# import logging
from django.conf import settings
# from django.conf import settings
from troggle.core.models_caves import Cave, NewSubCave
from utils import save_carefully
# from troggle.core.models_caves import Cave, NewSubCave
# from utils import save_carefully
def getLinksInCaveDescription(cave):
'''
Returns all HTML <a href> tags from a given cave as a list of tuples
in the format ('filename.html','Description')
'''
pattern='<a href=\"(.*?)\">(.*?)</a>'
if cave.underground_description:
return re.findall(pattern,cave.underground_description)
else:
return []
# def getLinksInCaveDescription(cave):
# '''
# Returns all HTML <a href> tags from a given cave as a list of tuples
# in the format ('filename.html','Description')
# '''
# pattern='<a href=\"(.*?)\">(.*?)</a>'
# if cave.underground_description:
# return re.findall(pattern,cave.underground_description)
# else:
# return []
def importSubcaves(cave):
for link in getLinksInCaveDescription(cave):
try:
subcaveFilePath=os.path.join(
settings.EXPOWEB,
os.path.dirname(cave.description_file),
link[0])
subcaveFile=open(subcaveFilePath,'rb')
description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8')
# def importSubcaves(cave):
# for link in getLinksInCaveDescription(cave):
# try:
# subcaveFilePath=os.path.join(
# settings.EXPOWEB,
# os.path.dirname(cave.description_file),
# link[0])
# subcaveFile=open(subcaveFilePath,'rb')
# description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8')
#lookupAttribs={'title':link[1], 'cave':cave}
#nonLookupAttribs={'description':description}
lookupAttribs={}
nonLookupAttribs={}
newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs)
# #lookupAttribs={'title':link[1], 'cave':cave}
# #nonLookupAttribs={'description':description}
# lookupAttribs={}
# nonLookupAttribs={}
# newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs)
logging.info("Added " + str(newSubcave) + " to " + str(cave))
except IOError:
logging.info("Subcave import couldn't open "+subcaveFilePath)
# logging.info("Added " + str(newSubcave) + " to " + str(cave))
# except IOError:
# logging.info("Subcave import couldn't open "+subcaveFilePath)
def getLinksInSubcaveDescription(subcave):
pattern='<a href=\"(.*?)\">(.*?)</a>'
if subcave.description:
return re.findall(pattern,subcave.description)
else:
return []
# def getLinksInSubcaveDescription(subcave):
# pattern='<a href=\"(.*?)\">(.*?)</a>'
# if subcave.description:
# return re.findall(pattern,subcave.description)
# else:
# return []
def getLinksInAllSubcaves():
bigList=[]
for subcave in NewSubCave.objects.all():
bigList+=getLinksInSubcaveDescription(subcave)
return bigList
# def getLinksInAllSubcaves():
# bigList=[]
# for subcave in NewSubCave.objects.all():
# bigList+=getLinksInSubcaveDescription(subcave)
# return bigList
def importAllSubcaves():
for cave in Cave.objects.all():
importSubcaves(cave)
# def importAllSubcaves():
# for cave in Cave.objects.all():
# importSubcaves(cave)