Indentation

main
Bob Mottram 2020-10-18 13:53:23 +01:00
parent 43096d087a
commit 574dc9d975
1 changed files with 58 additions and 57 deletions

View File

@ -262,39 +262,40 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
if addHashtag.startswith('#'): if addHashtag.startswith('#'):
if addHashtag not in hashtags: if addHashtag not in hashtags:
hashtags.append(addHashtag) hashtags.append(addHashtag)
htId = addHashtag.replace('#', '') htId = addHashtag.replace('#', '')
if validHashTag(htId): if validHashTag(htId):
hashtagUrl = \ hashtagUrl = \
httpPrefix + "://" + domainFull + "/tags/" + htId httpPrefix + "://" + domainFull + "/tags/" + htId
newTag = { newTag = {
'href': hashtagUrl, 'href': hashtagUrl,
'name': addHashtag, 'name': addHashtag,
'type': 'Hashtag' 'type': 'Hashtag'
} }
# does the tag already exist? # does the tag already exist?
addTagObject = None addTagObject = None
for t in postJsonObject['object']['tag']: for t in postJsonObject['object']['tag']:
if t.get('type') and t.get('name'): if t.get('type') and t.get('name'):
if t['type'] == 'Hashtag' and \ if t['type'] == 'Hashtag' and \
t['name'] == addHashtag: t['name'] == addHashtag:
addTagObject = t addTagObject = t
break break
# append the tag if it wasn't found # append the tag if it wasn't found
if not addTagObject: if not addTagObject:
postJsonObject['object']['tag'].append(newTag) postJsonObject['object']['tag'].append(newTag)
# add corresponding html to the post content # add corresponding html to the post content
hashtagHtml = \ hashtagHtml = \
" <a href=\"" + hashtagUrl + \ " <a href=\"" + hashtagUrl + \
"\" class=\"mention hashtag\" " + \ "\" class=\"mention hashtag\" " + \
"rel=\"tag\">#<span>" + \ "rel=\"tag\">#<span>" + \
htId + "</span></a>" htId + "</span></a>"
content = postJsonObject['object']['content'] content = postJsonObject['object']['content']
if content.endswith('</p>'): if hashtagHtml not in content:
content = \ if content.endswith('</p>'):
content[:len(content) - len('</p>')] + \ content = \
hashtagHtml + '</p>' content[:len(content) - len('</p>')] + \
else: hashtagHtml + '</p>'
content += hashtagHtml else:
content += hashtagHtml
postJsonObject['object']['content'] = content postJsonObject['object']['content'] = content
storeHashTags(baseDir, 'news', postJsonObject) storeHashTags(baseDir, 'news', postJsonObject)
# actionOccurred = True # actionOccurred = True
@ -305,30 +306,30 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
if rmHashtag.startswith('#'): if rmHashtag.startswith('#'):
if rmHashtag in hashtags: if rmHashtag in hashtags:
hashtags.remove(rmHashtag) hashtags.remove(rmHashtag)
htId = rmHashtag.replace('#', '') htId = rmHashtag.replace('#', '')
hashtagUrl = \ hashtagUrl = \
httpPrefix + "://" + domainFull + "/tags/" + htId httpPrefix + "://" + domainFull + "/tags/" + htId
# remove tag html from the post content # remove tag html from the post content
hashtagHtml = \ hashtagHtml = \
"<a href=\"" + hashtagUrl + \ "<a href=\"" + hashtagUrl + \
"\" class=\"mention hashtag\" " + \ "\" class=\"mention hashtag\" " + \
"rel=\"tag\">#<span>" + \ "rel=\"tag\">#<span>" + \
htId + "</span></a>" htId + "</span></a>"
content = postJsonObject['object']['content'] content = postJsonObject['object']['content']
if hashtagHtml in content: if hashtagHtml in content:
content = \ content = \
content.replace(hashtagHtml, '').replace(' ', ' ') content.replace(hashtagHtml, '').replace(' ', ' ')
postJsonObject['object']['content'] = content postJsonObject['object']['content'] = content
rmTagObject = None rmTagObject = None
for t in postJsonObject['object']['tag']: for t in postJsonObject['object']['tag']:
if t.get('type') and t.get('name'): if t.get('type') and t.get('name'):
if t['type'] == 'Hashtag' and \ if t['type'] == 'Hashtag' and \
t['name'] == rmHashtag: t['name'] == rmHashtag:
rmTagObject = t rmTagObject = t
break break
if rmTagObject: if rmTagObject:
postJsonObject['object']['tag'].remove(rmTagObject) postJsonObject['object']['tag'].remove(rmTagObject)
# actionOccurred = True # actionOccurred = True
# Block this item # Block this item
if actionStr.startswith('block') or actionStr.startswith('drop'): if actionStr.startswith('block') or actionStr.startswith('drop'):