diff --git a/core/views/other.py b/core/views/other.py index 88d0589..b590f21 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -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"", "\n"+frontmatter , logbookfile) + else: + logbookfile = re.sub(r"", f"\n

Expo {year}

\n", logbookfile) + dir = Path(settings.EXPOWEB) / "years" / year filepath = Path(dir, filename) diff --git a/parsers/imports.py b/parsers/imports.py index 3723ce3..cd27726 100644 --- a/parsers/imports.py +++ b/parsers/imports.py @@ -43,8 +43,9 @@ def import_logbooks(): def import_logbook(year=2019): print(f"-- Importing Logbook {year}") - with transaction.atomic(): - troggle.parsers.logbooks.LoadLogbook(year, format="blog") + print(f"-- - commented out") + # with transaction.atomic(): + # troggle.parsers.logbooks.LoadLogbook(year, format="cucc") def import_QMs(): print("-- Importing old QMs for 161, 204, 234 from CSV files") diff --git a/parsers/logbooks.py b/parsers/logbooks.py index ccd935f..25da271 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -51,8 +51,13 @@ data for old logbooks. New design needed, with a mechanism for flagging fixtures ''' MAX_LOGBOOK_ENTRY_TITLE_LENGTH = 200 -DEFAULT_LOGBOOK_PARSER = "parser_html" +BLOG_PARSER_SETTINGS = { + "2017": ("ukcavingblog.html", "parser_blog"), + "2019": ("ukcavingblog.html", "parser_blog"), + "2022": ("ukcavingblog.html", "parser_blog"), + } DEFAULT_LOGBOOK_FILE = "logbook.html" +DEFAULT_LOGBOOK_PARSER = "parser_html" # All years since 2010 use the default value for Logbook parser # but several don't work, and are skipped by the parsing code, e.g. 1983 LOGBOOK_PARSER_SETTINGS = { @@ -89,11 +94,11 @@ LOGBOOK_PARSER_SETTINGS = { "1982": ("log.htm", "parser_html_01"), } -entries = { "2022": 64, "2019": 56, "2018": 74, "2017": 60, "2016": 81, "2015": 79, +entries = { "2022": 64, "2019": 56, "2018": 75, "2017": 61, "2016": 81, "2015": 79, "2014": 65, "2013": 51, "2012": 75, "2011": 68, "2010": 22, "2009": 52, "2008": 49, "2007": 111, "2006": 60, "2005": 55, "2004": 76, "2003": 42, "2002": 31, - "2001": 48, "2000": 54, "1999": 79, "1998": 43, "1997": 53, "1996": 94, "1995": 41, - "1994": 32, "1993": 41, "1992": 61, "1991": 38, "1990": 87, "1989": 1,"1988": 1,"1987": 1, + "2001": 48, "2000": 54, "1999": 79, "1998": 43, "1997": 53, "1996": 95, "1995": 42, + "1994": 32, "1993": 41, "1992": 62, "1991": 39, "1990": 87, "1989": 1,"1988": 1,"1987": 1, "1985": 24, "1984": 32, "1983": 52, "1982": 42,} # Logbooks log.htm exist for 1983, 84, 85, 87, 88, 89 but have no full-working parser, or need hand-editing. @@ -258,7 +263,7 @@ def ParseDate(tripdate, year): return datetime.date(1970, 1, 1) # (2006 - not any more), 2008 - 2009 -def wiki_parser(year, expedition, txt): +def wiki_parser(year, expedition, txt, seq=""): global logentries global logdataissues @@ -300,10 +305,20 @@ def wiki_parser(year, expedition, txt): # 2002, 2004, 2005, 2007, 2010 - now # 2006 wiki text is incomplete, but the html all there. So using this parser now. -def parser_html(year, expedition, txt): +def parser_html(year, expedition, txt, seq=""): global logentries global logdataissues + # extract front material and stash for later use when rebuilding from list of entries + headmatch = re.match(r"(?i)(?s).*]*>(.*?)0): + frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html") + with open(frontpath,"w") as front: + front.write(headpara+"\n") + tripparas = re.findall(r"([\s\S]*?)(?=]*>(.*?)0): + frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html") + with open(frontpath,"w") as front: + front.write(headpara+"\n") + tripparas = re.findall(r"([\s\S]*?)(?= {{logbook_entries.0.expedition}} Expo Logbook + - -

Expo {{logbook_entries.0.expedition}}

{%for logbook_entry in logbook_entries%}