summaryrefslogtreecommitdiffstats
path: root/parsers/logbooks.py
diff options
context:
space:
mode:
authorSam Wenham <sam@wenhams.co.uk>2019-03-31 15:39:53 +0100
committerSam Wenham <sam@wenhams.co.uk>2019-03-31 15:39:53 +0100
commit9df91b221b4992d29b90caa30ae5a417d5b750d0 (patch)
treedfd69110a1af8ce3442c47f590bb129ee323a3f1 /parsers/logbooks.py
parent64a4842dcbcbe10c5edb057c0000659f2809c1f9 (diff)
downloadtroggle-9df91b221b4992d29b90caa30ae5a417d5b750d0.tar.gz
troggle-9df91b221b4992d29b90caa30ae5a417d5b750d0.tar.bz2
troggle-9df91b221b4992d29b90caa30ae5a417d5b750d0.zip
Support html and wiki logbook entrys
Move nearest_station to nearest_station_name and make nearest_station a foreign key to SurvexStation Lots of tidying
Diffstat (limited to 'parsers/logbooks.py')
-rw-r--r--parsers/logbooks.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index fbe00a3..cecbdb3 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -45,7 +45,7 @@ def GetTripPersons(trippeople, expedition, logtime_underground):
author = res[-1][0]
return res, author
-def GetTripCave(place): #need to be fuzzier about matching here. Already a very slow function...
+def GetTripCave(place): #need to be fuzzier about matching here. Already a very slow function...
# print "Getting cave for " , place
try:
katastNumRes=[]
@@ -74,23 +74,23 @@ def GetTripCave(place): #need to be fuzzier about matching h
noncaveplaces = [ "Journey", "Loser Plateau" ]
-def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground):
+def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground, entry_type="wiki"):
""" saves a logbook entry and related persontrips """
trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground)
if not author:
- print(" - skipping logentry" + title + " no author for entry")
+ print(" - Skipping logentry: " + title + " no author for entry")
return
-
-# tripCave = GetTripCave(place)
- #
+
+ #tripCave = GetTripCave(place)
+
lplace = place.lower()
if lplace not in noncaveplaces:
cave=GetCaveLookup().get(lplace)
#Check for an existing copy of the current entry, and save
expeditionday = expedition.get_expedition_day(date)
- lookupAttribs={'date':date, 'title':title}
- nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50]}
+ lookupAttribs={'date':date, 'title':title}
+ nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50], 'entry_type':entry_type}
lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
for tripperson, time_underground in trippersons:
@@ -177,7 +177,9 @@ def Parseloghtmltxt(year, expedition, txt):
ltriptext = re.sub(r"</p>", "", triptext)
ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
ltriptext = re.sub(r"<p>", "\n\n", ltriptext).strip()
- EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
+ EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext,
+ trippeople=trippeople, expedition=expedition, logtime_underground=0,
+ entry_type="html")
if logbook_entry_count == 0:
print(" - No trip entrys found in logbook, check the syntax matches htmltxt format")
@@ -226,7 +228,9 @@ def Parseloghtml01(year, expedition, txt):
#print ldate, trippeople.strip()
# could includ the tripid (url link for cross referencing)
- EnterLogIntoDbase(date=ldate, place=tripcave, title=triptitle, text=ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
+ EnterLogIntoDbase(date=ldate, place=tripcave, title=triptitle, text=ltriptext,
+ trippeople=trippeople, expedition=expedition, logtime_underground=0,
+ entry_type="html")
# parser for 2003
def Parseloghtml03(year, expedition, txt):
@@ -255,7 +259,9 @@ def Parseloghtml03(year, expedition, txt):
ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
ltriptext = re.sub(r"<p>", "\n\n", ltriptext).strip()
ltriptext = re.sub(r"[^\s0-9a-zA-Z\-.,:;'!&()\[\]<>?=+*%]", "_NONASCII_", ltriptext)
- EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
+ EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle,
+ text = ltriptext, trippeople=trippeople, expedition=expedition,
+ logtime_underground=0, entry_type="html")
def SetDatesFromLogbookEntries(expedition):