From 43dfe946b6385037141b94b775112037fe5f032f Mon Sep 17 00:00:00 2001 From: Sam Wenham Date: Mon, 24 Feb 2020 15:04:07 +0000 Subject: Just removing dud whitespace --- utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'utils.py') diff --git a/utils.py b/utils.py index ffb9f66..a6c8539 100644 --- a/utils.py +++ b/utils.py @@ -23,12 +23,12 @@ def randomLogbookSentence(): #Choose again if there are no sentances (this happens if it is a placeholder entry) while len(re.findall('[A-Z].*?\.',randSent['entry'].text))==0: randSent['entry']=LogbookEntry.objects.order_by('?')[0] - + #Choose a random sentence from that entry. Store the sentence as randSent['sentence'], and the number of that sentence in the entry as randSent['number'] sentenceList=re.findall('[A-Z].*?\.',randSent['entry'].text) randSent['number']=random.randrange(0,len(sentenceList)) randSent['sentence']=sentenceList[randSent['number']] - + return randSent @@ -37,10 +37,10 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}): -if instance does not exist in DB: add instance to DB, return (new instance, True) -if instance exists in DB and was modified using Troggle: do nothing, return (existing instance, False) -if instance exists in DB and was not modified using Troggle: overwrite instance, return (instance, False) - + The checking is accomplished using Django's get_or_create and the new_since_parsing boolean field defined in core.models.TroggleModel. - + """ instance, created=objectType.objects.get_or_create(defaults=nonLookupAttribs, **lookupAttribs) @@ -49,17 +49,17 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}): for k, v in list(nonLookupAttribs.items()): #overwrite the existing attributes from the logbook text (except date and title) setattr(instance, k, v) instance.save() - + if created: logging.info(str(instance) + ' was just added to the database for the first time. \n') - + if not created and instance.new_since_parsing: logging.info(str(instance) + " has been modified using Troggle, so the current script left it as is. \n") if not created and not instance.new_since_parsing: logging.info(str(instance) + " existed in the database unchanged since last parse. It was overwritten by the current script. \n") return (instance, created) - + re_body = re.compile(r"\]*\>(.*)\", re.DOTALL) re_title = re.compile(r"\]*\>(.*)\", re.DOTALL) @@ -80,7 +80,7 @@ def get_single_match(regex, text): def href_to_wikilinks(matchobj): """ Given an html link, checks for possible valid wikilinks. - + Returns the first valid wikilink. Valid means the target object actually exists. """ @@ -91,7 +91,7 @@ def href_to_wikilinks(matchobj): return matchobj.group() #except: #print 'fail' - + re_subs = [(re.compile(r"\]*\>(.*?)\", re.DOTALL), r"'''\1'''"), (re.compile(r"\(.*?)\", re.DOTALL), r"''\1''"), @@ -107,7 +107,7 @@ re_subs = [(re.compile(r"\]*\>(.*?)\", re.DOTALL), r"'''\1'''"), (re.compile(r"\(.*?)\", re.DOTALL), r"[[cavedescription:\1|\2]]"), #assumes that all links with target ids are cave descriptions. Not great. (re.compile(r"\[\([^\s]*).*?\\]", re.DOTALL), r"[[qm:\1]]"), (re.compile(r'.*)"?>(?P.*)'),href_to_wikilinks), - + ] def html_to_wiki(text, codec = "utf-8"): -- cgit v1.2.3