2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 16:27:07 +00:00

parse several UK caving blogs per year - working

This commit is contained in:
2022-12-16 19:57:56 +00:00
parent 5e9fd7fd77
commit f80e4efed8
4 changed files with 129 additions and 78 deletions

View File

@@ -27,11 +27,9 @@ Also has code to download a logbook in a choice of formats (why?!)
'''
todo = '''
- Check that the logbookdownloader works by testing with a round trip.
- Use it to convert all older logbooks into the 2005-variant of HTML then we can
get rid of the parsers for older formats. There are no images stored in the database,
so this is only a tool for a first pass, to be followed by extensive hand-editing!
- Use logbookdownloader to convert all older logbooks into the 2005-variant of HTML then we can
get rid of the parsers for older formats.
When we have done all the old logbooks, delete this function and the two templates.
@@ -152,7 +150,7 @@ def exportlogbook(request,year=None,extension=None):
for the current year. Formats available are HTML2005 (others old & broken or not written yet)
There are no images stored in the database, so this is only a tool for a first pass, to be followed by
hand-editing. However links to images work int he HTML text of a logbook entry
hand-editing. However links to images work in the HTML text of a logbook entry
NEED TO ADD IN THE MATERIAL WHICH IS NOT IN ANY LBE ! e.g. front matter.
@@ -183,6 +181,18 @@ def exportlogbook(request,year=None,extension=None):
response['Content-Disposition'] = 'attachment; filename='+filename
t=loader.get_template(template)
logbookfile = (t.render({'logbook_entries':logbook_entries}))
frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html")
if frontpath.is_file():
try:
with open(frontpath,"r") as front:
frontmatter = front.read()
except:
print(" ! Very Bad Error opening " + frontpath)
logbookfile = re.sub(r"<body>", "<body>\n"+frontmatter , logbookfile)
else:
logbookfile = re.sub(r"<body>", f"<body>\n<h1>Expo {year}</h1>\n", logbookfile)
dir = Path(settings.EXPOWEB) / "years" / year
filepath = Path(dir, filename)