Adding and removing tags

main
Bob Mottram 2020-10-18 10:19:38 +01:00
parent 086826b9a1
commit 10d4010cd8
1 changed files with 25 additions and 4 deletions

View File

@ -269,11 +269,23 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
if validHashTag(htId): if validHashTag(htId):
hashtagUrl = \ hashtagUrl = \
httpPrefix + "://" + domainFull + "/tags/" + htId httpPrefix + "://" + domainFull + "/tags/" + htId
postJsonObject['object']['tag'][htId] = { newTag = {
'href': hashtagUrl, 'href': hashtagUrl,
'name': addHashtag, 'name': addHashtag,
'type': 'Hashtag' 'type': 'Hashtag'
} }
# does the tag already exist?
addTagObject = None
for t in postJsonObject['object']['tag']:
if t.get('type') and t.get('name'):
if t['type'] == 'Hashtag' and \
t['name'] == addHashtag:
addTagObject = t
break
# append the tag if it wasn't found
if not addTagObject:
postJsonObject['object']['tag'].append(newTag)
# add corresponding html to the post content
hashtagHtml = \ hashtagHtml = \
" <a href=\"" + hashtagUrl + \ " <a href=\"" + hashtagUrl + \
"\" class=\"mention hashtag\" " + \ "\" class=\"mention hashtag\" " + \
@ -296,9 +308,10 @@ 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 = addHashtag.replace('#', '') htId = rmHashtag.replace('#', '')
hashtagUrl = \ hashtagUrl = \
httpPrefix + "://" + domainFull + "/tags/" + htId httpPrefix + "://" + domainFull + "/tags/" + htId
# remove tag html from the post content
hashtagHtml = \ hashtagHtml = \
"<a href=\"" + hashtagUrl + \ "<a href=\"" + hashtagUrl + \
"\" class=\"mention hashtag\" " + \ "\" class=\"mention hashtag\" " + \
@ -309,7 +322,15 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
content = \ content = \
content.replace(hashtagHtml, '').replace(' ', ' ') content.replace(hashtagHtml, '').replace(' ', ' ')
postJsonObject['object']['content'] = content postJsonObject['object']['content'] = content
del postJsonObject['object']['tag'][htId] rmTagObject = None
for t in postJsonObject['object']['tag']:
if t.get('type') and t.get('name'):
if t['type'] == 'Hashtag' and \
t['name'] == rmHashtag:
rmTagObject = t
break
if rmTagObject:
postJsonObject['object']['tag'].remove(rmTagObject)
# actionOccurred = True # actionOccurred = True
# Block this item # Block this item