tidy and comments

This commit is contained in:
Philip Sargent 2022-12-10 13:00:57 +00:00
parent cabcada0b8
commit 0e47909704
2 changed files with 48 additions and 47 deletions

View File

@ -93,7 +93,7 @@ entries = { "2022": 64, "2019": 56, "2018": 74, "2017": 60, "2016": 81, "2015":
"2008": 49, "2007": 111, "2006": 60, "2005": 55, "2004": 76, "2003": 42, "2002": 31, "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, "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, "1994": 32, "1993": 41, "1992": 61, "1991": 38, "1990": 87, "1989": 1,"1988": 1,"1987": 1,
"1985": 24,"1984": 32,"1983": 52,"1982": 42,} "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. # Logbooks log.htm exist for 1983, 84, 85, 87, 88, 89 but have no full-working parser, or need hand-editing.
logentries = [] # the entire logbook for one year is a single object: a list of entries logentries = [] # the entire logbook for one year is a single object: a list of entries
@ -471,57 +471,58 @@ def parser_html_01(year, expedition, txt):
print(message) print(message)
return return
# parser for 2003 # parser for 2003. Retired after conversion of the logbook.html
def parser_html_03(year, expedition, txt): # KEEP THIS COMMENTED-OUT example until after we have doen the same thing with the html_01 parser
global logentries # def parser_html_03(year, expedition, txt):
global logdataissues # global logentries
# global logdataissues
tripparas = re.findall(r"<hr\s*/>([\s\S]*?)(?=<hr)", txt) # tripparas = re.findall(r"<hr\s*/>([\s\S]*?)(?=<hr)", txt)
logbook_entry_count = 0 # logbook_entry_count = 0
for trippara in tripparas: # for trippara in tripparas:
logbook_entry_count += 1 # logbook_entry_count += 1
tid = set_trip_id(year,logbook_entry_count) # default trip id, before we read the date # tid = set_trip_id(year,logbook_entry_count) # default trip id, before we read the date
s = re.match(r"(?s)\s*<p>(.*?)</p>(.*)$", trippara) # s = re.match(r"(?s)\s*<p>(.*?)</p>(.*)$", trippara)
if not ( s ) : # if not ( s ) :
message = " ! - Skipping logentry {year} on failure to parse parser_html_03: {} {} {}...".format(tid,s,trippara[:300]) # message = " ! - Skipping logentry {year} on failure to parse parser_html_03: {} {} {}...".format(tid,s,trippara[:300])
DataIssue.objects.create(parser='logbooks', message=message) # DataIssue.objects.create(parser='logbooks', message=message)
logdataissues[tid]=message # logdataissues[tid]=message
print(message) # print(message)
break # break
tripheader, triptext = s.group(1), s.group(2) # tripheader, triptext = s.group(1), s.group(2)
tripheader = re.sub(r"&nbsp;", " ", tripheader) # tripheader = re.sub(r"&nbsp;", " ", tripheader)
tripheader = re.sub(r"\s+", " ", tripheader).strip() # tripheader = re.sub(r"\s+", " ", tripheader).strip()
sheader = tripheader.split(" -- ") # sheader = tripheader.split(" -- ")
tu = "" # tu = ""
if re.match("T/U|Time underwater", sheader[-1]): # if re.match("T/U|Time underwater", sheader[-1]):
tu = sheader.pop() # not a number in 2003 usually # tu = sheader.pop() # not a number in 2003 usually
# print(f" - {logbook_entry_count} '{tu}' ") # # print(f" - {logbook_entry_count} '{tu}' ")
if len(sheader) != 3: # if len(sheader) != 3:
print(" ! Header not three pieces for parser_html_03() ", sheader) # print(" ! Header not three pieces for parser_html_03() ", sheader)
tripdate, triptitle, trippeople = sheader # tripdate, triptitle, trippeople = sheader
ldate = ParseDate(tripdate.strip(), year) # ldate = ParseDate(tripdate.strip(), year)
# print(f" - {logbook_entry_count} '{ldate}' from '{tripdate.strip()}' ") # # print(f" - {logbook_entry_count} '{ldate}' from '{tripdate.strip()}' ")
# print(f" - {logbook_entry_count} '{trippeople}' ") # # print(f" - {logbook_entry_count} '{trippeople}' ")
titlelist = triptitle.split(" , ") # titlelist = triptitle.split(" , ")
if len(titlelist) >= 2: # if len(titlelist) >= 2:
location, *namelist = titlelist # list unpacking operator # location, *namelist = titlelist # list unpacking operator
tripname = ", ".join(namelist) # concatenate strings # tripname = ", ".join(namelist) # concatenate strings
# print(f" - {logbook_entry_count} {location} '{tripname}'") # # print(f" - {logbook_entry_count} {location} '{tripname}'")
else: # else:
location = "UNKNOWN" # location = "UNKNOWN"
ltriptext = triptext + "<br /><br />\n\n" + tu # ltriptext = triptext + "<br /><br />\n\n" + tu
ltriptext = re.sub(r"</p>", "", ltriptext) # ltriptext = re.sub(r"</p>", "", ltriptext)
#ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext) # #ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
ltriptext = re.sub(r"<p>", "<br /><br />\n\n", ltriptext).strip() # ltriptext = re.sub(r"<p>", "<br /><br />\n\n", ltriptext).strip()
#ltriptext = re.sub(r"[^\s0-9a-zA-Z\-.,:;'!&()\[\]<>?=+*%]", "_NONASCII_", ltriptext) # #ltriptext = re.sub(r"[^\s0-9a-zA-Z\-.,:;'!&()\[\]<>?=+*%]", "_NONASCII_", ltriptext)
entrytuple = (ldate, location, tripname, ltriptext, # entrytuple = (ldate, location, tripname, ltriptext,
trippeople, expedition, tu, tid) # trippeople, expedition, tu, tid)
logentries.append(entrytuple) # logentries.append(entrytuple)
def LoadLogbookForExpedition(expedition): def LoadLogbookForExpedition(expedition):

View File

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
<!-- templates/logbookentry.html - this text visible because this template has been included --> <!-- templates/logbookentry.html - this text visible because this template has been included -->
{% block title %}Logbook {{logbookentry.id}}{% endblock %} {% block title %}Logbook {{logbookentry.expedition.name}}{% endblock %}
{% block content %} {% block content %}
{% block related %}{% endblock %} {% block related %}{% endblock %}