From 0f5109cb0988d76c5b7d3037acca0ad8ac07f0dd Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:38:18 +0100 Subject: [svn] new person expedition Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8189 by julian @ 1/18/2009 7:50 PM --- parsers/logbooks.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'parsers/logbooks.py') diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 53726c6..a2cf58a 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -169,10 +169,20 @@ def Parseloghtml01(year, expedition, txt): triptitles = triptitle.split(" - ") tripcave = triptitles[0].strip() - ltriptext = re.sub("

", "", triptext) + ltriptext = triptext + + mtail = re.search('(?:[^<]*|\s|/|-|&||\((?:same day|\d+)\))*$', ltriptext) + if mtail: + #print mtail.group(0) + ltriptext = ltriptext[:mtail.start(0)] + ltriptext = re.sub("

", "", ltriptext) ltriptext = re.sub("\s*?\n\s*", " ", ltriptext) - ltriptext = re.sub("

", "\n\n", ltriptext).strip() + ltriptext = re.sub("

|
", "\n\n", ltriptext).strip() #ltriptext = re.sub("[^\s0-9a-zA-Z\-.,:;'!]", "NONASCII", ltriptext) + ltriptext = re.sub("", "_", ltriptext) + ltriptext = re.sub("", "''", ltriptext) + ltriptext = re.sub("", "'''", ltriptext) + #print ldate, trippeople.strip() # could includ the tripid (url link for cross referencing) @@ -246,6 +256,28 @@ def SetDatesFromLogbookEntries(expedition): expedition.date_to = max([personexpedition.date_to for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_to] or [None]) expedition.save() + # order by appearance in the logbook (done by id) + lprevlogbookentry = None + for logbookentry in expedition.logbookentry_set.order_by('id'): + logbookentry.logbookentry_prev = lprevlogbookentry + if lprevlogbookentry: + lprevlogbookentry.logbookentry_next = logbookentry + lprevlogbookentry.save() + logbookentry.logbookentry_next = None + logbookentry.save() + lprevlogbookentry = logbookentry + + # order by date for setting the references + lprevlogbookentry = None + for logbookentry in expedition.logbookentry_set.order_by('date'): + if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date: + mcount = re.search("_(\d+)$", lprevlogbookentry.href) + mc = mcount and (int(mcount.group(1)) + 1) or 1 + logbookentry.href = "%s_%d" % (logbookentry.date, mc) + else: + logbookentry.href = "%s" % logbookentry.date + logbookentry.save() + lprevlogbookentry = logbookentry def LoadLogbookForExpedition(expedition): @@ -268,6 +300,7 @@ def LoadLogbooks(): models.LogbookEntry.objects.all().delete() expowebbase = os.path.join(settings.EXPOWEB, "years") #yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite + #yearlinks = [ ("1997", "1997/log.htm", Parseloghtml01),] # overwrite for year, lloc, parsefunc in yearlinks: expedition = models.Expedition.objects.filter(year = year)[0] -- cgit v1.2.3